String fileName = dir + File.separator + date + File.separator + (file.list().length + 1) + ".txt"; File file = new File(fileName); BufferedWriter writer = null; FileOutputStream writerStream = new FileOutputStream(file); writer = new BufferedWriter(new OutputStreamWriter(writerStream, "UTF-8")); StringBuilder strBuild = new StringBuilder(); writer.write(strBuild.toString());
注意上面的代码最好放在catch中,然后在finally中添加
writer.flush();
writer.close();
参考链接:https://blog.csdn.net/dunceiam/article/details/43190609