Java 文件写入不覆盖的写法
FileOutputStream o = null;
File file = null;
FileWriter fw = null;
byte[] buff = new byte[]{};
try {
file = new File("F:\\data.txt");
if (!file.exists()) {
file.createNewFile();
}
for (需要遍历的数据) {
String s = "组装的信息" + "\r\n";
buff = s.getBytes();
o = new FileOutputStream(file, true);
o.write(buff);
o.flush();
o.close();
}
System.out.println("写数据成功!");
} catch (IOException | ParseException e) {
e.printStackTrace();
}
本文来自博客园,作者:程序员hg,转载请注明原文链接:https://www.cnblogs.com/hg-blogs/p/17096096.html