1

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 update in that file.

On Seeing this How to write files to assets folder or raw folder in android?

I allow the user to set password ie writing the pass into the file then read the pass and validate if it matches. Is it possible to Write file in Raw Folder

Community
  • 1
  • 1
Praveenbabu
  • 85
  • 1
  • 2
  • 13

5 Answers5

4

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.

Andro Selva
  • 53,910
  • 52
  • 193
  • 240
  • [ ]http://stackoverflow.com/questions/5973568/save-the-data-using-shared-preference-in-android. I read this but the problem in that i need to run this in device. but it fails if i do that.So i cant go for **Shared Preferences** Please give anyother suggestion in later i plan to do sending sms from one mobile to other on matching sms text is matches with password then it will lock the device. For this wat data storage should i use ?. now i should not use file,sqlite and shared – Praveenbabu May 16 '12 at 13:01
  • Ty for responding Andro selva. Is that shared preference data is persistent on device after restart ? – Praveenbabu May 16 '12 at 13:27
3

No,it's not possible to write file in raw folder

you should use shared prefrence for that.

http://samir-mangroliya.blogspot.in/p/android-shared-preferences.html

Samir Mangroliya
  • 39,918
  • 16
  • 117
  • 134
2

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.

Avadhani Y
  • 7,566
  • 19
  • 63
  • 90
2

Any data present in the "res" folder is not writable. You can only read data from it.

-1

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

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

    try {
  outputStream = openFileOutput(filename, Context.MODE_PRIVATE);
  outputStream.write(string.getBytes());
  outputStream.close();
} catch (Exception e) {
  e.printStackTrace();
}
drew7721
  • 1,622
  • 18
  • 20
  • This say only how to write into files to the internal or external storage, not for writing into files in raw folder in Android. – rbrisuda Jan 09 '17 at 11:28