打印流复制文件 – 恵玩科技

package IO.com.lxgyx_03;

/*
 * 需求:DataStreamDemo.java复制到Copy.java中
 * 数据源:
 * 		DataStreamDemo.java -- 读取数据 -- FileReader -- BufferedReader
 * 目的地:
 * 		Copy.java -- 写出数据 -- FileWriter -- BufferedWriter -- PrintWriter
 */

import java.io.*;

public class CopyFileDemo {
    public static void main(String[] args) throws IOException {
        //复制文件
        BufferedReader br=new BufferedReader(new FileReader("test\\hello.java"));
        PrintWriter pr=new PrintWriter(new FileWriter("test\\Copy.java"),true);

        String line=null;
        while ((line=br.readLine())!=null){
            pr.println(line);
        }
        System.out.println("复制成功");
        br.close();
        pr.close();
    }
}

 

打赏作者