Re: [android-developers] Re: very urgent.. problem in writing file..
Before , writing to SDCARD - its preferred to get the state of it. private boolean isSDCARDMounted(){ String status = Environment.getExternalStorageState(); if (status.equals(Environment.MEDIA_MOUNTED)) return true; return false; } http://developer.android.com/intl/de/reference/android/os/Environment.html On Sat, Mar 13, 2010 at 1:57 PM, Bob Kerns wrote: > Resources aren't even IN the filesystem. They're packaged up in > the .apk file, and are read-only. > > You CAN write to the application's private storage area. This will > work even if the device does not have an SD card. However, this > storage is limited; it may be better for you to use the SD card. > > In your example, you give it a path that refers to several levels of > directory that don't exist - and openFileOutput() is documented as > taking a file NAME, not a path. But you can use getDir(name, mode) to > create a directory (and control access) and then create files in that > via the normal Java APIs. > > If you choose to put it on the SD card, follow TreKing's advice, > except the API is called Environment.getExternalStorageDirectory(). > You can do > > File myDir = new File(Environment.getExternalStorageDirectory(), > getPackageName()) > mydir.mkdir(); > Writer out = new FileWriter(myDir); > > But since you seem to be concerned about the large amount of data, you > may want to change how you approach it. The resource can be the > default data, and you put additional data or new data that replaces it > in a file. Your application would first consult the file, and if not > found, it would then consult the resource. This would avoid the need > to copy the resource out into the filesystem to modify it. > > On Mar 12, 6:07 am, RV wrote: > > Hi, > > I am stuck on this for a very long. > > I have my txt file in res/raw/myfile.txt. > > I want to append some text into this file. But I am unable to do so. > > I used the code as follows: > > > > FileOutputStream out = context.openFileOutput( > > > "res/raw/myfile.txt", > > > Context.MODE_WORLD_WRITEABLE > > | > Context.MODE_APPEND); > > > > OutputStreamWriter osw = new > OutputStreamWriter(out); > > > >osw.write(entry); > >osw.flush(); > >osw.close(); > > > > It is not giving any error but also do nothing to my file. > > > > Also How could I edit only the 1st line of my file. (my file contain > > huge data.) > > > > Any help will be appreciated. > > > > Thank you > > > > RV > > -- > You received this message because you are subscribed to the Google > Groups "Android Developers" group. > To post to this group, send email to android-developers@googlegroups.com > To unsubscribe from this group, send email to > android-developers+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/android-developers?hl=en > -- --kumaresan -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: very urgent.. problem in writing file..
Resources aren't even IN the filesystem. They're packaged up in the .apk file, and are read-only. You CAN write to the application's private storage area. This will work even if the device does not have an SD card. However, this storage is limited; it may be better for you to use the SD card. In your example, you give it a path that refers to several levels of directory that don't exist - and openFileOutput() is documented as taking a file NAME, not a path. But you can use getDir(name, mode) to create a directory (and control access) and then create files in that via the normal Java APIs. If you choose to put it on the SD card, follow TreKing's advice, except the API is called Environment.getExternalStorageDirectory(). You can do File myDir = new File(Environment.getExternalStorageDirectory(), getPackageName()) mydir.mkdir(); Writer out = new FileWriter(myDir); But since you seem to be concerned about the large amount of data, you may want to change how you approach it. The resource can be the default data, and you put additional data or new data that replaces it in a file. Your application would first consult the file, and if not found, it would then consult the resource. This would avoid the need to copy the resource out into the filesystem to modify it. On Mar 12, 6:07 am, RV wrote: > Hi, > I am stuck on this for a very long. > I have my txt file in res/raw/myfile.txt. > I want to append some text into this file. But I am unable to do so. > I used the code as follows: > > FileOutputStream out = context.openFileOutput( > "res/raw/myfile.txt", > > Context.MODE_WORLD_WRITEABLE > | > Context.MODE_APPEND); > > OutputStreamWriter osw = new > OutputStreamWriter(out); > > osw.write(entry); > osw.flush(); > osw.close(); > > It is not giving any error but also do nothing to my file. > > Also How could I edit only the 1st line of my file. (my file contain > huge data.) > > Any help will be appreciated. > > Thank you > > RV -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Re: very urgent.. problem in writing file..
On Fri, Mar 12, 2010 at 10:34 PM, Kumar Bibek wrote: > FileWriter fw = new FileWriter("/sdcard/text.txt"); > AGAIN - DO NOT hard code the SD card path. Use Context.getExternalStorageDirectory(). This path may change in the future or from device to device and you're app will fail if you hard code this value. - TreKing - Chicago transit tracking app for Android-powered devices http://sites.google.com/site/rezmobileapps/treking -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: very urgent.. problem in writing file..
Try this, FileWriter fw = new FileWriter("/sdcard/text.txt"); fw.write("some text"); fw.flush(); fw.close(); Thanks and Regards, Kumar Bibek On Mar 13, 9:19 am, Farproc wrote: > Basically you can not modify the resources of your app. > They are read-only after build. > > You can write data to sd card and modify it then use. > > On Mar 12, 10:07 pm, RV wrote: > > > Hi, > > I am stuck on this for a very long. > > I have my txt file in res/raw/myfile.txt. > > I want to append some text into this file. But I am unable to do so. > > I used the code as follows: > > > FileOutputStream out = context.openFileOutput( > > > > "res/raw/myfile.txt", > > > > Context.MODE_WORLD_WRITEABLE > > | > > Context.MODE_APPEND); > > > OutputStreamWriter osw = new > > OutputStreamWriter(out); > > > osw.write(entry); > > osw.flush(); > > osw.close(); > > > It is not giving any error but also do nothing to my file. > > > Also How could I edit only the 1st line of my file. (my file contain > > huge data.) > > > Any help will be appreciated. > > > Thank you > > > RV -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] Re: very urgent.. problem in writing file..
Basically you can not modify the resources of your app. They are read-only after build. You can write data to sd card and modify it then use. On Mar 12, 10:07 pm, RV wrote: > Hi, > I am stuck on this for a very long. > I have my txt file in res/raw/myfile.txt. > I want to append some text into this file. But I am unable to do so. > I used the code as follows: > > FileOutputStream out = context.openFileOutput( > "res/raw/myfile.txt", > > Context.MODE_WORLD_WRITEABLE > | > Context.MODE_APPEND); > > OutputStreamWriter osw = new > OutputStreamWriter(out); > > osw.write(entry); > osw.flush(); > osw.close(); > > It is not giving any error but also do nothing to my file. > > Also How could I edit only the 1st line of my file. (my file contain > huge data.) > > Any help will be appreciated. > > Thank you > > RV -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en