How to write to .txt file in assets folder.
How to get path assets folder ?
You can't. The assets folder is read-only at runtime.
Pick a different location to save your data, see Data Storage for more information.
The path of assets folder is file:///android_asset But this is read-only.
The assets folder is like folders res, src, gen, etc. These are all useful to provide different files as input to build system to generate APK file for your app.
All these are read-only while your app is running. At run-time you can only write to SD card.
I hope you understand my answer.
Not possible,
Better you choose internal storage to save your txt file. Internal Storage. Hope this will help you to understand.
No you can't do this, because of if you read and write both at runtime then everything could be change and application will behave unexpected which could be harmful or may be crashed. i suggest you to use internal memory, sqlite and app SharedPreferences etc.
Related
I have been searching around and can not seem to find a way to download a media file from my website and save it to my app's raw resource folder. What is the best way to do this? Any help is greatly appreciated.
You can't access resource folder once your app is installed. So you can't access raw folder for WRITE after installation. So better to use internal storage to store this file.
You cannot do that, you can only read from the 'raw' and 'assets' folders. Either use internal storage, or if relevant - APK Expansion Files.
Following are my understanding of them, and want to make sure it's correct.
Assets folder is a directory that I can place files so app can use.
This is immutable folder.
Internal storage is a directory you are given when your app is installed.
You can mutate files under this directory.
If I maintain a read-write sqlite database, I will probably make it here under internal storage.
If I want to provide an initial database though, I would have to place it under the assets folder, and copy it when app is first run.
Yes, your understanding is correct. The difference between the Assets folder and the Internal Storage folder is that the Assets folder can't be changed at runtime. So the usage of internal storage and assets folder is as follows-
1) When one has fixed content like fonts,images,styles,string values,etc. put it into the assets folder.
2) If based on the programme the values must change based on the situation then save those values in the Internal Storage.
Yes you're right. The difference is that assets folder is read only folder. You can put your files there and use them in your app but if you need to change or modify them, you should copy them from assets to internal then do your works, so if you have static texts or fonts or files that needs nochange you can put them in assets folder but if you have database files you should copy ithem to internal.
My application downloads files from the server and save them somewhere. Where should I put the folder to save the files? Not in assets right? Should I create a folder somewhere parallel to "bin"/"libs"/"res" folder?
Another question: should I put the downloaded files in internal storage or external storage?
Actually you can not save the downloaded file in either of this folders because they are not allowed to make modification at run time.
Best option goes according to your requirement, as if you file is too large and you are not much worried about it's security then you can store them on SDCARD(External storage). and if your file is small enough and much secure then you should save them on internal storage.
Check most popular application store their files on SDCARD but encrypted way...
Hope this ans your question
Store your downloaded files in a folder on an external storage directory. like
String yourFolderPath = Environment.getExternalStorageDirectory() + /com.yourapp/;
Store files in that folder.
if its just few files, it would be safer and more convenient to use the context.getCacheDir(). with it, you can be sure that it will always be there unlike sdcard which can be locked when the phone is in storage mode. it doesnt require manifest permission. You don't even have to worry about security unless your user is rooted.
I am developing an android application and i need to read words from a file to create a Trie. Is there a way i can write the file to internal storage on install so that only my application can access it, or should i hard code the words. Any suggestions are appreciated
If the file isn't going to change, you should put it in your assets directory. If it is going to change, you can copy it from your assets to internal storage and it'll be private. External storage (often an SD card) is word-readable.
http://developer.android.com/guide/topics/data/data-storage.html
http://developer.android.com/reference/android/content/res/AssetManager.html
i have a file in the asset folder, and when i press a button in my program i have to move that file in a sub-folder(run-time). Can it be done?
i have to do this:
assets/file.txt -> assets/aaa/file.txt
No your assets are compiled into your apk file. Consider storing a persistent preference marking whatever you are trying to do instead.
No, you can't do it. You can't write anything inside the assets folder programmatically. Better option is to use internal storage. You can use Files Folder in the internal storage. See getFilesDir() in the docs.
Reason: Once you have an .apk file it is read only, so you can't add, delete or modify in it,
Alternate:
though you can use the sqlite DB for the purpose... where you can save file in hierarchy using blob type and you can modify it through queries...