MappedByteBuffer读取大文件

RandomAccessFile randomAccessFile = new RandomAccessFile(file,"rw");

FileChannel fileChannel = randomAccessFile.getChannel();

long size = fileChannel.size();

MappedByteBuffer mappedByteBuffer = fileChannel.map(FileChannel.MapMode.READ_WRITE,0,size);

for ( int i = 0 ; i < size; i++){
    byte b = mappedByteBuffer.get(i);
    mappedByteBuffer.put(i,b);
}
randomAccessFile.close();
fileChannel.close();
file = null;
fileChannel = null;
size = 0;
mappedByteBuffer = null;

猜你喜欢

转载自u010991855.iteye.com/blog/2281204