我IOException: Map Failed
在尝试编写大字节数组时得到了。我使用下面的方法将字节数组写入文件
private static void write(byte[] data) throws Exception {
File file = new File("C:/temp/file.json");
int length = data.length;
RandomAccessFile raf = new RandomAccessFile(file, "rw");
FileChannel fc = raf.getChannel();
MappedByteBuffer buffer = fc.map(FileChannel.MapMode.READ_WRITE, 0, length);
for (int i = 0; i < length; i++) {
buffer.put(data[i]);
}
}
字节数组约为 270mb。谁能解释我做错了什么?谢谢。