JavaSE-19.2.3【案例-复制Java文件(打印流改进版)】
1 package day10.lesson2; 2 3 import java.io.*; 4 5 /* 6 2.5 案例-复制Java文件(打印流改进版) 7 */ 8 public class CopyJavaDemo { 9 public static void main(String[] args) throws IOException { 10 /*BufferedReader br = new BufferedReader(new FileReader("stage2\\src\\day10\\lesson2\\SystemInAndOutDemo.java")); 11 BufferedWriter bw = new BufferedWriter(new FileWriter("stage2\\day9_lesson2_copy\\CopySystemInAndOutDemo.java")); 12 13 String line; 14 while ((line=br.readLine()) != null){ 15 bw.write(line); 16 bw.newLine(); 17 bw.flush(); 18 } 19 20 bw.close(); 21 br.close();*/ 22 23 //打印流改进 24 BufferedReader br = new BufferedReader(new FileReader("stage2\\src\\day10\\lesson2\\SystemInAndOutDemo.java")); 25 PrintWriter pw = new PrintWriter(new FileWriter("stage2\\day9_lesson2_copy\\CopySystemInAndOutDemo.java"), true); 26 27 String line; 28 while ((line=br.readLine()) != null){ 29 pw.println(line); 30 } 31 32 pw.close(); 33 br.close(); 34 } 35 }