java nio实现文件复制

public class TransferTo {
    public static void main(String[] args) throws Exception {
        FileChannel in = new FileInputStream("src/demo20/data.txt").getChannel(),
                out = new FileOutputStream("src/demo20/data2.txt").getChannel();
        in.transferTo(0, in.size(), out);
        
    }

}

通过nio来实现,transferTo方法即可实现.真的简单,不用写循环什么的,具体方法参考文档.

posted @ 2019-03-25 22:44  随意的马蒂洛克  阅读(1576)  评论(0编辑  收藏  举报