public class NioFileCopyOutJVM {
public static void main(String[] args) throws IOException {
long l1 = System.currentTimeMillis() ;
FileChannel input = FileChannel.open(Paths.get("H:/e-touch-etx.zip"), StandardOpenOption.READ);
FileChannel output = FileChannel.open(Paths.get("H:/e-touch-bak.zip"), StandardOpenOption.WRITE, StandardOpenOption.READ, StandardOpenOption.CREATE);
MappedByteBuffer inMapBuffer = input.map(FileChannel.MapMode.READ_ONLY, 0, input.size());
MappedByteBuffer outMapBuffer = output.map(FileChannel.MapMode.READ_WRITE, 0, input.size());
byte[] dst = new byte[inMapBuffer.limit()];
inMapBuffer.get(dst) ;
outMapBuffer.put(dst);
input.close();
output.close();
System.out.println("耗时时间 "+(System.currentTimeMillis() - l1));
}
}
nio内存映射方式复制文件
最新推荐文章于 2024-12-13 08:00:00 发布