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方法即可实现.真的简单,不用写循环什么的,具体方法参考文档.