本文共 597 字,大约阅读时间需要 1 分钟。
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("复制完毕");}}
转载地址:http://jllxo.baihongyu.com/