BufferReader BufferWriter

Copying information from one file to another with 'BufferReader BufferWriter'

public class Demo5 {
 public static void main(String[] args) {
 //data cache
  try {
   FileReader fileReader = new FileReader("C:/Users/caich5/Desktop/aaaa.txt");
   FileWriter fileWriter = new FileWriter("C:/Users/caich5/Desktop/bbbb.txt");
   
   BufferedReader reader = new BufferedReader(fileReader);
   BufferedWriter writer = new BufferedWriter(fileWriter);
   
   String line = null;
   while((line=reader.readLine())!= null){
    writer.write(line);
    writer.newLine();
    writer.flush();
   }
   writer.close();
   reader.close();
  } catch (Exception e) {
   e.printStackTrace();
  }
 }
}

posted @ 2018-03-06 09:38  Chris,Cai  阅读(282)  评论(0编辑  收藏  举报