44

I want to create some pre-created files when my Android application is installed.

I would like to create the file in both the internal memory (data/data//files/) and in a newly created sdcard directories (/sdcard//data1/).

How can I do this?

Willi Mentzel
  • 27,862
  • 20
  • 113
  • 121
Xarph
  • 1,429
  • 3
  • 17
  • 26

3 Answers3

44

If you have a larger number of files and a directory structure you should use /assets. These are not given any R-constants and can be scanned by your application

To open an asset-file:

InputStream is = getAssets().open("path/file.ext");

To list a directory:

String[] files = getAssets().list("");
Mikpa
  • 1,912
  • 15
  • 20
  • 3
    I think this is the correct answer. also see http://developer.android.com/reference/android/content/res/AssetManager.html#list(java.lang.String) and http://developer.android.com/tools/projects/index.html – likejudo Apr 28 '14 at 00:28
42

You can save you files in \res\raw and write the code to store this files to the desired locations if it does not exist when the app start.
Check this to access the internal memory and sdcard
and access the raw file using the following

InputStream databaseInputStream = getResources().openRawResource(R.raw.yourfile);
Labeeb Panampullan
  • 34,521
  • 28
  • 94
  • 112
2

It is worth mentioning that really large amounts of data can be dealt with APK Expansion Files.

In 2016, Google Play currently requires that your APK file be no more than 100MB. For most applications, this is plenty of space.

The APK size limit increases from time to time, so it's meaningful to check the current digit.

18446744073709551615
  • 16,368
  • 4
  • 94
  • 127