Trouble with filewriter overwriting files instead of appending to the end

Make sure that when you create an instance of a FileWriter, that you are appending to the end of it. This can be done by using this specific FileWriter constructor which takes an additional boolean as a second parameter. This boolean tells the FileWriter to append to the end of the file, rather than overwriting the file.

BufferedWriter outStream= new BufferedWriter(new FileWriter("encoded.txt", true));

Leave a Comment