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方法即可实现.真的简单,不用写循环什么的,具体方法参考文档.
本文介绍了一种使用Java NIO的FileChannel进行文件复制的方法。通过调用transferTo方法,可以轻松地将一个文件的内容复制到另一个文件中,而无需手动编写循环进行读写操作。
1704

被折叠的 条评论
为什么被折叠?



