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方法即可實現.真的簡單,不用寫循環什么的,具體方法參考文檔.
