Java IO流的操作基本规律-需求体现

需求1:复制一个文本文件

BufferedReader bufr=new BufferedReader(new FileReader("C:\\demo.txt"));
BufferedWriter bufw=new BufferedWriter(new FileWriter("C:\\demo(复件).txt"));
String line = null;
while ((line = bufr.readLine()) != null){
   bufw.write(line);
   bufw.newLine();
   bufw.flush();
}
bufr.close();
bufw.close();


需求2:读取键盘录入信息,并写入到一个文本文件中。并输入over时,程序写入完毕

BufferedReader bufr=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufw=new BufferedWriter(new FileWriter("C:\\b.txt"));
String line=null;
while((line=bufr.readLine())!=null){
   bufw.write(line);
   bufw.newLine();
   bufw.flush();
}
bufr.close();
bufw.close();


需求3:将一个文本文件数据显示在控制台上。

BufferedReader bufr=new BufferedReader(new FileReader("C:\\b.txt"));
BufferedWriter bufw=new BufferedWriter(new OutputStreamWriter(System.out));
String line=null;
while((line=bufr.readLine())!=null){
   bufw.write(line);
   bufw.newLine();
   bufw.flush();
}
bufr.close();
bufw.close();


需求4:读取键盘录入数据,并显示在控制台上。

BufferedReader bufr=new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bufw=new BufferedWriter(new OutputStreamWriter(System.out));
String line=null;
while((line=bufr.readLine())!=null){
   bufw.write(line);
   bufw.newLine();
   bufw.flush();
}
bufr.close();
bufw.close();