This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
how we can remove a file from the assets folder at runtime in android?
Is it possible to create a file in assets folder when an application is run and delete the same file when the app is stopped.
For asset you have read file permission only. So you cannot create / delete files in assets folder. Following are the restrictions applied to assets folder.
1) Only Read Permission available for this folder.
2) File size for placing inside the assets limit to 10 MB.If you want to place
then the larger file should be placed as chunk.
3) You can use this folder, for placing files like database file, font file etc...
Don't fight with it. It is not a proper way of dealing with files using assets folder.
You can use SDcard that is suitable location for creating and deleting files
You can use standard method for placing files in SDcard through app,
Environment.getExternalStoragePublicDirectory("filetype");
The apk is read only and the assets/ folder is not modifiable at runtime, which sounds like something you may be seeking. Check this question
Related
This question already has answers here:
Where to put text files in directory in Android
(3 answers)
Closed 4 years ago.
In Android Studio, If we want to use an image in our Anroid app, we move this image to res/drawable file. And we use it.
But if we want to use contents of a .txt file (e.g reading text from file at the first launch the app), which directory should we move this file?
You can put it on res/raw or in assets/ directory.
Just create folder assets like this:
Or create folder raw in res and you can put there whatever you want:
It depends on using file.For example for reading text file, any movement is needed. You can read it from asset directory.
But if you want to write in a text file, you must move it to internal/external memory in a directory you have set in your code.
Suppose I store various images in raw folder. However, my own code first learns of the file names at runtime. (It reads a text configuration file at startup.) Is it possible to then search "raw" folder in my android app and if found, load image from raw into imageview?
Okay, thanks to Mario I got on track to doing some research. These 5 SO's explain everything:
Android images in /assets or res/raw
Reading assets or raw or resource files as a File object in Android
How to reference a File in raw folder in Android
Check for file existence in androids assets folder?
Difference between /res and /assets directories
This question already has answers here:
Can the Android layout folder contain subfolders?
(20 answers)
Closed 9 years ago.
Of course I can right click the raw folder and add new folder but when I export the project, the APK file does not contain the new sub folder.
You can't.
The folders in /res/ have a predefined structure, and you can't add subfolders.
However, seeing as this is the raw folder, you may want to look into using the assets folder, in which sub folders are supported.
Keep in mind thought that by using assets you won't be able to use R.*.* references anymore. You will have to go through the AssetManager.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Can The Android drawable directory contain subdirectories?
How to organize graphics/java/xml file in folders in android project in eclipse?
I mean - should I (to store graphics) create folder in my 'drawable-mdpi' or as a separated folder?
I tried making folder in drawable and calling file by:
#drawable/photo/fileName
also tried making separate folder in /res, and call by:
#photo/fileName
but with no success.
should I (to store graphics) create folder in my 'drawable-mdpi' or as a separated folder?
Sadly, you cannot create your own file structure in the /res folder... You must use the existing folder structure, like /res/drawable-mdpi and use R.drawable.xxx.
You can read about this "bug" here: Android layout folder organization or read the brief explanation straight from a lead Android programmer: Can The Android drawable directory contain subdirectories?.
You don't need/can't use a separate folder. Just put in each drawable folder and access with #drawable/filename with no extension
I'm trying to develop an application for android...
The question is, I need to Edit or create(if not existing already) an XML file in the Resources folder or Assets folder(anyone will do)...How can I do that?
I can get the XML file to open from the Assets folder using the
getAssets().
But I need to modify its contents and store it again somewhere....
I don't want to save it on the memory card....Please Help...
I hope you guys will do....Thanks in advance...
The question is, I need to Edit or create(if not existing already) an XML file in the Resources folder or Assets folder(anyone will do)...How can I do that?
You don't. Assets and resources are read-only at runtime.
But I need to modify its contents and store it again somewhere
Store it in a file using Java file I/O.