java - Android - Persist file when app closes -


I am creating a file in my Android application, as follows:


 

HEADINGSTRING = New string ("Android debugging" + "\ n" "XML Test debugging"); } Public Zero Setup Logging (Reference Reference) {Log D. ("Logging", "setting logging ..."); Try {// fileOutputStream fOut = context.openFileOutput (FILE_NAME, Context.MODE_APPEND), below IOException; OutputStream Water OSV = New OutputStream Water (FOUT); // Write a string in the file osw.write (HEADINGSTRING); / * Make sure everything * is actually written and close * / osw.flush (); Osw.close (); } Hold (FileNotFoundException e) {e.printStackTrace (); } Hold (IOException e) {e.printStackTrace (); } Finally {Log D. ("Logging", "Preparing setup ..."); }}


And I write the file while running this app:


  public zero addToLog (file file, string text ) IOException throws {BufferedWriter bw = new BufferedWriter (new FileWriter (file, true)); Bw.write ("\ n" + text); Bw.newLine (); Bw.flush (); Bw.close (); }  

It works fine but when my app stops, the file is deleted and when the app is replayed then what I wrote is All information has expired.

How can I ensure that the file remains closed even after the app is closed?

Update:

I changed MODE_PRIVATE to MODE_APPEND and the problem is OK, thanks skirmish.

You want to check, int) Particularly about MODE_APPEND, instead of clearing everything, every When the bar app starts


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -