I am having a file in the folder res/raw/a.xml.
I want to write some data to this file?
How it can be done in Android?
How can we access a file stored in local directory in order to write data to that file.
can anyone help me in sorting out this issue ?
Thanks in Advance,
Hi, I am having a file in the folder res/raw/a.xml. I want to write some data to this file? How it can be done in Android?
You cannot modify a resource at runtime, sorry.
How can we access a file stored in local directory in order to write data to that file.
Use getFilesDir() to get a File object pointing to your app's local directory. Then, use standard Java I/O.
Related
I have code for creating an internal file, there is random algorithem that create the data stored in it and i want any app to have the same file with the same binary data in it.
so i need to make the file on my desktop and add it to internal files some how.
my question is what do you think is the best way to do it.
i thought to locate it in my project, read it, and write it to internal files.
the problem is, i dont know where to locate my file in android studio so that it will be included in the external files and then where to read it from.
thanks. =]
hope i made myself clear.
Put it in src/main/assets/.
You can then access your file with AssetManager and do whatever you want with it.
From the Android Developers website:
main/assets/
This is empty. You can use it to store raw asset files. Files that you
save here are compiled into an .apk file as-is, and the original
filename is preserved. You can navigate this directory in the same way
as a typical file system using URIs and read files as a stream of
bytes using the AssetManager. For example, this is a good location for
textures and game data.
You need to move that into the assets folder. From there you can refer to the file.
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...
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.
I want to save data from internet in asset folder in Android. I used Eclipse IDE to develop the android application.
How i can achieve this ?
Thanks.
The assets directory is readonly. It's defined and initialized at compile time, you cannot add or edit its contents.
Source (note it doesn't mention anything about writing to files...only reading them.)
Use the SDCard for such operations.
slote is right . use internal file storage/SD Card or sqLite database to save image
I'm trying to simply get the filename of a file from an online directory. The directory only has one file in it. The filename is actually the version number. If the filename is "newer" than the file that I already have stored on the android, it will download the file and replace it. I already know how to download the file. I'm not sure if android has some sort of built-in directory lister or if I need to create a PHP file that will display the files, then somehow open and read that in and use that as my path. Any help would be greatly appreciated.
You'll want to write that PHP script to return the file name. With that, you can do a straight download from the server.