String path=System.getProperty("java.io.tmpdir");
BufferedWriter bw = null;
StringBuilder sb = new StringBuilder();
sb.append("a").append("\n");
sb.append("b");
try {
File file = new File(path, "TestCar.txt");
if (!file.exists()) {
file.createNewFile();
}
bw = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(file), "GBK"));
bw.write(sb.toString());
} catch (Exception e2) {
e2.printStackTrace();
} finally {
if (bw != null) {
try {
bw.flush();
bw.close();
} catch (Exception e3) {
e3.printStackTrace();
}
}
}
获取系统临时文件目录,生成txt文件
最新推荐文章于 2023-07-31 16:20:15 发布