I am getting IOException: Map Failed when trying to write a large byte array. I use the method below to write a byte array to a file
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]);
}
}
The byte array is about 270mb. Can anyone explain what I am doing wrong? Thanks.