¥0.1
MappedByteBuffer支持的最大空间是多少?
1个回答
0
采纳
FileChannel实现类FileChannelImpl中的map方法有这样的代码段:
else if(var4 > 2147483647L) {
throw new IllegalArgumentException("Size exceeds Integer.MAX_VALUE");
}
其中var4参数就是我们初始化MappedByteBuffer使用的方法,可见MappedByteBuffer支持的最大大小是2147482647Byte。即int的最大值。
MappedByteBuffer的使用:
File file = new File("文件地址");
RandomAccessFile raf = new RandomAccessFile(file, "rw");
FileChannel fc = raf.getChannel();
MappedByteBuffer out = fc.map(FileChannel.MapMode.READ_WRITE, 0, length);
撰写回答