Java NIO之用Channel和MappedByteBuffer高效快速复制大文件

NIO的应用,复制大文件,超爽,简单高效

import java.io.RandomAccessFile;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.channels.FileChannel.MapMode;

public class Demo05 {
public static void main(String[] args) throws Exception {
    FileChannel inChannel=new RandomAccessFile("f:\\01.wmv", "r").getChannel();
    FileChannel outChannel=new RandomAccessFile("f:\\02.wmv", "rw").getChannel();
    
    MappedByteBuffer map=inChannel.map(MapMode.READ_ONLY, 0, inChannel.size());
    
    outChannel.write(map);
    outChannel.close();
    inChannel.close();
    System.out.println("复制完毕");
}
}
上一篇:IDG资本发布2017年TMT投资趋势:出海崛起,To C复燃,寻找下一个增量市场


下一篇:nginx服务