import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
public class WriteToFile {
public static void main(String[] args) {
try (FileWriter writer = new FileWriter("example.txt"); BufferedWriter buffer = new BufferedWriter(writer)) {
// 写入文件
buffer.write("第一行文本");
// 换行
buffer.newLine();
System.out.println("文件写入成功!");
} catch (IOException e) {
e.printStackTrace();
}
}
}
标签:java,buffer,写入,BufferedWriter,io,FileWriter,逐行
From: https://www.cnblogs.com/xuhu/p/17341389.html