我当前正在使用FileWriter创建和写入文件。有什么方法可以每次都写入同一个文件而不删除其中的内容?
FileWriter
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打开“追加”模式。
true
fout = new FileWriter("filename.txt", true);