nio 本地文件操作之通道之间的数据传输

来源:互联网 发布:ubuntu touch命令 编辑:程序博客网 时间:2024/05/21 09:35
//开启通道新方式
FileChannel inChannel = FileChannel.open(Paths.get("E:/Program Files/NIO/nio.zip"),StandardOpenOption.READ);
FileChannel ouChannel = FileChannel.open(Paths.get("E:/Program Files/NIO/nio2.zip"),StandardOpenOption.READ,StandardOpenOption.WRITE,StandardOpenOption.CREATE);

//利用通道之间的传输来复制数据,实际用的是内存映射的方式
inChannel.transferTo(0, inChannel.size(), ouChannel);

inChannel.close();
ouChannel.close();
System.out.println("game over...");
阅读全文
0 0