BufferedReader_WriterDemo Myth丶恋晨 2022-08-10 10:55 116阅读 0赞 import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.File; import java.io.FileReader; import java.io.FileWriter; public class BufferedReader\_WriterDemo \{ public static void main(String\[\] args) \{ method(); \} private static void method() \{ File file = new File("d:\\\\a\\\\a.txt"); //获取文件路径; BufferedWriter bw = null; BufferedReader br = null; try \{ bw = new BufferedWriter(new FileWriter(file)); char\[\] c = \{'a', 'b', 'c'\}; bw.write(c); //将数组内容写入; bw.newLine(); //换行; bw.write("aaaa"); //继续写入内容; bw.flush(); //刷新; br = new BufferedReader(new FileReader(file)); String line = null; while((line = br.readLine()) != null) \{ System.out.println(line); //输出内容; \} br.close(); //关闭流 bw.close(); \} catch (Exception e) \{ e.printStackTrace(); \} \} \}
还没有评论,来说两句吧...