Android - Persist file when app closes <p>I am creating a file in my Android application as follows:</p> <hr> <pre><code>HEADINGSTRING = new String("Android Debugging " + "\n" "XML test Debugging"); } public void setUpLogging(Context context){ Log.d("LOGGING", "Setting up logging....."); try { // catches IOException below FileOutputStream fOut = context.openFileOutput(FILE_NAME,Context.MODE_APPEND); OutputStreamWriter osw = new OutputStreamWriter(fOut); // Write the string to the file osw.write(HEADINGSTRING); /* ensure that everything is * really written out and close */ osw.flush(); osw.close(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally{ Log.d("LOGGING", "Finished logging setup....."); } } </code></pre> <hr> <p>And I write to the file during the running of the app as follows:</p> <hr> <pre><code>public void addToLog(File file, String text) throws IOException { BufferedWriter bw = new BufferedWriter (new FileWriter(file, true)); bw.write ("\n" + text); bw.newLine(); bw.flush(); bw.close(); } </code></pre> <hr> <p>This works fine but when my app closes the file gets deleted and when the app is run again all the information I wrote to it is gone.</p> <p>How can I make sure the file persists even after closure of the app?</p> <p><strong>Update:</strong></p> <p>I have changed MODE_PRIVATE to MODE_APPEND and the problem is fixed, thanks Skirmish.</p>