实现:从控制台读取要复制的源文件名和目标文件名,将源文件中的内容复制到目标文件中
1 public class CopyFile { 2 private static BufferedReader stdIn = 3 new BufferedReader( 4 new InputStreamReader(System.in))' 5 private static PrintWriter stdOut = 6 new PrintWriter(System.out, true);//标准结果 7 private static PrintWriter stdErr = 8 new PrintWriter(System.err, true);//提示信息或者错误信息 9 10 public static void main(String[] args) throws IOException { 11 stdErr.print("Source filename: "); 12 stdErr.flush();//保证将上述提示信息显示在屏幕上 13 14 BufferedReader input = new BufferedReader( 15 new FileReader(stdIn.readLine()));//读用户输入的内容 16 stdErr.print("Destination filename: "); 17 stdErr.flush(); 18 19 PrintWriter output = 20 new PrintWriter(new FileWriter(stdIn.readLine())); 21 String line = input.readLine(); 22 23 while (line!=null) { 24 output.println(line); 25 line = input.readLine(); 26 } 27 28 input.close(); 29 output.close(); 30 31 stdOut.println("done"); 32 }