Hi, Yes, I have added the permission and have installed SD card in emulator.
But how to l look at stack trace to see if got an exception and use android.os.Environment? Regards, Perumal On Mar 30, 11:03 pm, Mark Murphy <[email protected]> wrote: > perumal316 wrote: > > Hi All, > > > I am writing an application that will create a textfile in the /sdcard > > or /data directory and write messages to the textfile.Each time I want > > to append the messages and not overwrite the file. > > > I used the following code: > > > public void writeAlert(String message){ > > FileWriter f; > > try { > > f = new FileWriter("/sdcard/alert.txt"); > > f.write(message); > > f.flush(); > > f.close(); > > } catch (IOException e1) { > > // TODO Auto-generated catch block > > e1.printStackTrace(); > > } > > } > > > But there is no text file created. Any idea what's the problem with my > > code? Is this the correct way or is there any other way to create and > > write to a textfile? > > 1. Did you add the WRITE_EXTERNAL_STORAGE permission? > > 2. Did you look at your stack trace to see if you got an exception? > > 3. Does your device or emulator have an SD card installed? Note that the > emulator does not get an SD card image by default -- you have to > specifically say you want one when you create the AVD. > > Also, please use android.os.Environment and > getExternalStorageDirectory(), as /sdcard is the correct path on some > devices but not all. > > Also also, you probably want to use the FileWriter constructor that > takes a boolean parameter indicating that you want it to append. > > -- > Mark Murphy (a Commons > Guy)http://commonsware.com|http://twitter.com/commonsguy > > _Android Programming Tutorials_ Version 2.0 Available! -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en To unsubscribe from this group, send email to android-developers+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.

