I tried a simple file write program in Android.
try
{
//File f1=new File("/sdcard/Prag.txt");
File f1=new File("J:\\Prag.txt");
BufferedWriter out = new BufferedWriter(new FileWriter(f1,true));
out.write("Pragadheesh" + "\n");
out.close();
} catch (IOException ioe)
{ioe.printStackTrace();}
But the exception is getting hit. How can I fix this?
[edit]:
I tried File f1=new File(Environment.getExternalStorageDirectory() + "//Prag.txt");
and f1 value = /mnt/sdcard/Prag.txt
But still the exception gets hit. I have changed the permission too in manifest file
[solution]
As per Krishnabhadra’s reply, I had to Make sure your SDCard is not mounted on a PC
Android is based on linux so windows style paths like
"J:\\prag.txt"won’t work. In linux paths are like this:"/folder1/folder2/file.txt"Also don’t use hardcoded paths, because different phones might have different path for the SD card. Therefore you you should use
Environment.getExternalStorageDirectory()that gives the path to the SD card programmatically.So use:
Also add necessary permission by:
Inside your manifest, somewhere outside
applicationtag.