0

I have a file with some data that I want only my application to have access to. I was wondering in which folder I should put the file in my android project in order to have access to it using

File file = new File(context.getFilesDir(), filename);

Thanks

DeKekem
  • 589
  • 10
  • 20

3 Answers3

3

This is just an empty folder in Android device. To access your files in assets

InputStream is = getAssets().open("subfolder/anyfile.txt");

to access files inside raw use InputStream XmlFileInputStream = getResources().openRawResource(R.raw.somesrc);

getFilesDir() is just a folder that uses for openFileOutput(String, int) method. More detailed: https://stackoverflow.com/a/21230946/1979882

Community
  • 1
  • 1
Vyacheslav
  • 26,359
  • 19
  • 112
  • 194
1

Use Assets Folder For files that will be bundled with the application and will be stored inside the apk as is. you can add an "asset" folder to your project by right clicking your app in the project explorer then select

New=> Folder=> Assets Folder.

you can open the files stored in the assets folder using the assets manager for example to open an image kept in /assets/img/image1.png:

InputStream is = assetManager.open("img/image1.png");

for HTML files you can load the file by its URL :

webView.loadUrl("file:///android_asset/"+name);
sh.e.salh
  • 508
  • 2
  • 5
  • 16
0

Here you can get a clear functionality of saving,retrieving a file

Here is the Link:http://www.mysamplecode.com/2012/06/android-internal-external-storage.html

Rajakumar
  • 907
  • 1
  • 7
  • 17