try {
File file = new File(filePath+"usedcommands.txt");
if (!file.exists()) {
file.createNewFile();
}
FileWriter fw = new FileWriter(file.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(input+"\n");
bw.close();
} catch(Exception e) { System.out.println("can't write to usedcommands.txt..."); }
我正在写入一个 txt 文件,但每次我运行写入过程时,它都会覆盖已写入的内容。我如何更改我的代码,以便程序的这一部分不会覆盖已有的内容?
将 true 作为第二个参数传递给 FileWriter 以打开“追加”模式。
FileWriter fw = new FileWriter(file.getAbsoluteFile(), true);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)