Question

I'm opening large file (~ 200 MB) with RandomAccessFile and then get Channel for it. I'm trying to map some data to MappedByteBuffer, but I'm getting exception:

Channel not open for writing - cannot extend file for required size.

I can't figure out, why map method tries to write to the file - mapping area is smaller than file size! Why it's trying to extend file in this case?

Update

Problem solved, it turned out that I thought that 3rd parameter indicated for index position in file, that it was the length of the buffer.

Was it helpful?

Solution

From doc:

Parameters:

position The position within the file at which the mapped region is to start; must be non-negative

size The size of the region to be mapped; must be non-negative and no greater than java.lang.Integer.MAX_VALUE

What exactly the file size you have? Are you trying to map offset+size that exceeds the file size?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top