I am trying to write a file in Android.
private void writeScoreToFile(BlastScore result)
{
try{
FileWriter fstream = new FileWriter(CaptureActivity.BLAST_SCORES,true);
BufferedWriter out = new BufferedWriter(fstream);
out.write(Integer.toString(result.getBlastScore()));
out.close();
}catch (Exception e){
System.err.println("Write Error: " + e.getMessage());
}
}
I get the error:
10-28 21:04:11.200: W/System.err(669): Write Error: /BlastScores.txt (Read-only file system)
How can I resolve this?
You’re trying to write to the root directory. You probably want to be writing to your app’s directory, not root.
To do that, use Context.openFileInput and Context.openFileOutput instead of
new FileWriter.