带有追加模式的Java FileWriter [英] Java FileWriter with append mode
本文介绍了带有追加模式的Java FileWriter的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我目前正在使用 FileWriter
来创建和写入文件。有没有什么方法可以每次都写入同一个文件而不删除其中的内容?
I'm currently using FileWriter
to create and write to a file. Is there any way that I can write to the same file every time without deleting the contents in there?
fout = new FileWriter(
"Distribution_" + Double.toString(_lowerBound) + "_" + Double.toString(_highBound) + ".txt");
fileout = new PrintWriter(fout,true);
fileout.print(now.getTime().toString() + ", " + weight + ","+ count +"\n");
fileout.close();
推荐答案
传递 true
作为 FileWriter
的第二个参数,打开追加模式。
Pass true
as a second argument to FileWriter
to turn on "append" mode.
fout = new FileWriter("filename.txt", true);
这篇关于带有追加模式的Java FileWriter的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文