Skip to content Skip to sidebar Skip to footer

How To Write A File In Raw Folder In Android

In my task i need to read and write the file in Raw folder. I did the first one to read the file from my project, Now i want to Write the same file. So it easy for me to make any u

Solution 1:

Any data present in the "res" folder is not writable. You can only read data from it. You can never write data to res folder on the fly. If you are looking for a way to store username and password credentials, you can make use of Shared Prefrence

Here is an example on how to use it.

http://marakana.com/forums/android/examples/63.html

Edit 1

Storing data in Shared Preference is persistent unless user clears the data using "clear data" button in your settings page.Navigate to settings->manage apps->your app. Here you will be seeing uninstall button and clear data button. And one more thing in android is you will never be able to save a persistent data. You can't use any data storage methods like preference, sqlite or file system to store a data for permanent. If user wants to wipe the data he clicks on "Clear Data" button and your data are gone. So you have make your coding in such a way to handle this.

Since this is not possible, you could try to use your app's resources which is write protected and not possible to write to it. So it depends on user or you might have to use your server to store the data over there.

Solution 2:

Solution 3:

Yes, it cannot be done. Instead of trying to write in raw directory, Update your files in the local file system by using Shared Preferences as described in below link :

Please refer http://developer.android.com/guide/topics/data/data-storage.html#filesInternal.

Solution 4:

See this tutorial from the Android Dev site : http://developer.android.com/training/basics/data-storage/files.html

String filename = "myfile";
Stringstring = "Hello world!";
FileOutputStream outputStream;

    try {
  outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
  outputStream.write(string.getBytes());
  outputStream.close();
} catch (Exception e) {
  e.printStackTrace();
}

Post a Comment for "How To Write A File In Raw Folder In Android"