I tried to get the output of java program as a text file.but when i print output in a text file and for the next set of input it overwrites on it.I want to see all of my output in an order in a text file.How can I?
If using FileWriter
, pass true as a second argument to FileWriter to turn on "append" mode.
fout = new FileWriter("filename.txt", true);
FileWriter usage reference
Assuming you're using a FileWriter
, you can provide true
as the second parameter to the FileWriter(java.io.File, boolean)
or FileWriter(java.lang.String, boolean)
constructor, to indicate that you wish to append to the file, rather than overwriting.
It may be more efficient, however, to append everything to a StringBuilder
/StringBuffer
beforehand, and only write once.
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