IO 写入,文件内容追加与覆盖
File file = new File(path);
if (!file.exists()) {
file.mkdirs();
}
OutputStreamWriter out = null;
try {
out = new OutputStreamWriter(new FileOutputStream(stringPath, false),"UTF-8");
BufferedWriter writer = new BufferedWriter(out);
writer.write("hello world");
writer.flush();
writer.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(out);
}
以上执行会一直覆盖文件内容(新替换旧)
(new FileOutputStream(stringPath, true)
FileOutputStream 修改参数 false—>true(新追加在旧文件之后)