The problem is that the cursor, indicating the place where the OutputStreamWriter to the file, OutputStreamWriter at the very beginning of the file.
What you want to do is set it to the end of the file using the alternative FileOutputStream constructor, which has a boolean attribute, Fixed code:
if(myfile.exists()) { try { FileOutputStream fOut = new FileOutputStream(myfile, true); 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(); } }
source share