public class BufferedWriterDemo throws IOException { public static void main(String[] args) throws IOException { // 创建流对象 BufferedWriter bw = new BufferedWriter(new FileWriter("out.txt")); // 写出数据 bw.write("hello"); // 写出换行 bw.newLine(); bw.write("world"); bw.newLine(); bw.write("!"); bw.newLine(); // 释放资源 bw.close(); } }