Java写入并保存txt文件
1 package TEST;
2 import java.io.BufferedWriter;
3 import java.io.FileWriter;
4 import java.io.IOException;
5 public class BufferedWriterDemo {
6 public static void main(String[] args) throws IOException {
7
8 write("E:\\1.txt"); //运行主方法
9 }
10 public static void write(String path)
11 throws IOException {
12 //将写入转化为流的形式
13 BufferedWriter bw = new BufferedWriter(new FileWriter(path));
14 //一次写一行
15 String ss = "测试数据";
16 bw.write(ss);
17 bw.newLine(); //换行用
18
19 //关闭流
20 bw.close();
21 System.out.println("写入成功");
22 }
23
24
25 }