Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

Based on the error it is trying to write a file to the filesystem root. Your application is only allowed write to specific folders.

Found this on an article:

/data/data/your_project_package_structure/files/
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top