3、字节流输入输出实现文件的copy

程序代码

    //文件copy
    public static void main(String[] args) throws IOException {
//     获取源头
        File src = new File("F:\a.txt");
        File desc = new File("F:\b.txt");

        //选择流
        FileInputStream is = new FileInputStream(src);
        FileOutputStream os = new FileOutputStream(desc);

        //操作
        byte[] flush = new byte[1024];
        int len=-1;
        while ((len=is.read(flush))!=-1){
            os.write(flush,0,len);
        }

        //关闭
        os.flush();
        os.close();
        is.close();

    }

结果

原文地址:https://www.cnblogs.com/gfbzs/p/13762351.html