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     }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM