Writing Text File to Sd Card Fails

Writing a text file to SDCard gives a IllegalArgumentException in Android

openFileOuput() doesn't accept paths, only a file name.

Error writing to SD Card

openFileOutput() is for opening files in your program data folder, which is located on the internal memory, you may only supply the file name, not the path, hence the complain mnt/scard/PatRecords/testfile.txt contains a file separator.

if you want to open files on the SD card, you have to use FileOutputStream() or something like that:

File of = new File(Environment.getExternalStorageDirectory(), filename);
FileOutputStream fos = new FileOutputStream(file);
fos.write(data);
fos.flush();
fos.close();

Saving file on SD card gets an error

I used this command to unmount

umount /media/sdcard

And it saved the problem.



Related Topics



Leave a reply



Submit