emada.adame wrote:
> hi im just trying to save some text to a file on android and while it
> works fine on the emulator "dont crash", when i try it on my phone it
> crashes, what am i doing wrong? heres the code:
> 
>       try{
>           File root = Environment.getExternalStorageDirectory();
>           if (root.canWrite()){
>                File file = new File(root, "file.txt");
>                FileWriter writer = new FileWriter(file);
>                BufferedWriter out = new BufferedWriter(writer);
>                out.write("some data");
>                out.close();
>                showMes("File saved.");
>            }else{
>                  showMes("Could not save file.");
>            }
>       }catch(Exception e){
>             showMes(e.toString());
>       }
> 
> i do know it crashes on " File root =
> Environment.getExternalStorageDirectory(); "

That would be very surprising.

Make sure you have the WRITE_EXTERNAL_STORAGE permission. Make sure your
device has an SD card installed, and that it is not mounted on the
development PC as a USB drive.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Android Consulting: http://commonsware.com/consulting

-- 
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

Reply via email to