Reputation: 6029
I want to build a TXT
file and add new lines to it every time.
I don't want it to be in the app data
folder in external storage (default folder used in openFileOutput()
) since it's erased as the app uninstalled (This is a log meant for these issues).
How can it be done ?
Upvotes: 0
Views: 65
Reputation: 12919
Use FileWriter
. The constructor's second argument defines whether an existing file should be opened and appended.
FileWriter writer;
try {
writer = new FileWriter(yourFilePathHere, true);
writer.write("Hello World");
writer.flush();
writer.close();
} catch (IOException e) {
//Error handling
}
yourFilePathHere
might be new File(getExternalStorageDirectory(), "log.txt").getAbsolutePath()
;
Upvotes: 1