My code is :
if(myfile.exists()) {
try {
FileOutputStream fOut = new FileOutputStream(myfile);
OutputStreamWriter myOutWriter = new OutputStreamWriter(fOut);
for (LatLng item : markerArrayList) {
myOutWriter.append(item.toString());
}
myOutWriter.append("\n\n");
myOutWriter.close();
fOut.close();
Toast.makeText(getBaseContext(), "Done writing ", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(), e.getMessage(), Toast.LENGTH_SHORT).show();
}
}
When I use myOutWriter.append
, what really happens is that every time I'm writing to the file, it overwrites previous content.
That's because you do not use the append option of the FileOutputStream constructor.
You should use:
FileOutputStream fOut = new FileOutputStream(myfile, true);
instead, to open the file for appending.
Otherwise, it overwrites the contents of the previous file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With