Reputation: 1763
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
Upvotes: 0
Views: 3076
Reputation: 529
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);
Upvotes: 1
Reputation: 937
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
Upvotes: 0
Reputation: 27221
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
Upvotes: 3