Home >Java >javaTutorial >Java implements writing and saving txt files
java如何实现写入并保存txt文件?
(推荐学习:java视频教程)
实例代码如下:
package TEST; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.IOException; public class BufferedWriterDemo { public static void main(String[] args) throws IOException { write("E:\\1.txt"); //运行主方法 } public static void write(String path) throws IOException { //将写入转化为流的形式 BufferedWriter bw = new BufferedWriter(new FileWriter(path)); //一次写一行 String ss = "测试数据"; bw.write(ss); bw.newLine(); //换行用 //关闭流 bw.close(); System.out.println("写入成功"); } }
相关文章教程分享:java入门教程
The above is the detailed content of Java implements writing and saving txt files. For more information, please follow other related articles on the PHP Chinese website!