Android Java writing text file to sd card
- by Paul
I have a strange problem I've come across. My app can write a simple textfile to SD card and sometimes it works for some people but not for others and I have no idea why. Some people it force closes if they put some characters like "..." in it and such. I cannot seem to reproduce it as I've had no troubles but this is the code that handles it. Can anyone think of something that may lead to problems or a better to way to do it?
public void generateNoteOnSD(String sFileName, String sBody){
try
{
File root = new File(Environment.getExternalStorageDirectory(), "Notes");
if (!root.exists()) {
root.mkdirs();
}
File gpxfile = new File(root, sFileName);
FileWriter writer = new FileWriter(gpxfile);
writer.append(sBody);
writer.flush();
writer.close();
Toast.makeText(this, "Saved", Toast.LENGTH_SHORT).show();
}
catch(IOException e)
{
e.printStackTrace();
importError = e.getMessage();
iError();
}
}