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方法即可实现.真的简单,不用写循环什么的,具体方法参考文档.
原文地址:https://www.cnblogs.com/lishuaiqi/p/10597326.html
时间: 2024-10-01 00:39:21