BufferedReader与 BufferedWriter完成copy操作
作者:互联网
package com.io.writer; import java.io.*; /** * BufferedReader与 BufferedWriter完成copy操作 */ public class BufferedCopy_ { public static void main(String[] args) { String srcFilePath="d:\\ok.txt"; String destFilePath="d:\\ok2.txt"; BufferedReader bufferedReader=null; BufferedWriter bufferedWriter=null; String line; try { bufferedReader= new BufferedReader(new FileReader(srcFilePath)); bufferedWriter=new BufferedWriter(new FileWriter(destFilePath)); //readLine是读取一行的内容,但是没有换行 while ((line=bufferedReader.readLine())!=null){ //每读取一行就写入 bufferedWriter.write(line); //插入一个换行符 bufferedWriter.newLine(); } System.out.println("拷贝完毕"); } catch (IOException e) { e.printStackTrace(); } finally { //关闭流 try { if (bufferedReader!=null){ bufferedReader.close(); } if (bufferedWriter!=null){ bufferedWriter.close(); } } catch (IOException e) { e.printStackTrace(); } } } }
标签:null,bufferedReader,String,BufferedWriter,BufferedReader,bufferedWriter,new,copy 来源: https://www.cnblogs.com/cyy9310/p/16210621.html