Java 復(fù)制大文件方式(nio2 FileChannel 拷貝文件能力測試)
Java實現(xiàn)文件拷貝評測
JAVA Zero Copy
優(yōu)先選擇Path,MappedByteBuffer ,FileChannel,ByteBuffer
- Files.copy(Path source, Path target, CopyOption... options)
- FileChannel transferTo(long position, long count, WritableByteChannel target)
- FileChannel transferFrom(ReadableByteChannel src, long position, long count)
- MappedByteBuffer put(ByteBuffer src)
下圖只是為了看下復(fù)制效率,寫的有點亂

Paste_Image.png
總結(jié):
- 使用Files.copy()和MappedByteBuffer處理的復(fù)制速度很快
- 注意MappedByteBuffer map(MapMode mode, long position, long size)中size最大為Integer.MAX_VALUE,也就是2G ,超過2G的文件就要就不能一次復(fù)制完,可使用循環(huán)解決這個問題