I am using a RandomAccessFile in Java 6 but having some strange behavior when reading bytes.
With the following code, where offset
and data
are appropriately initialized:
int offset;
byte data[];
randFile.readFully(data, offset, data.length);
I get the following stack trace:
null
java.lang.IndexOutOfBoundsException
at java.io.RandomAccessFile.readBytes(Native Method)
at java.io.RandomAccessFile.read(RandomAccessFile.java:355)
at java.io.RandomAccessFile.readFully(RandomAccessFile.java:414)
BUT, with the same values of offset
and data
, the following (seemingly identical) code works fine!
randFile.seek(offset);
for (int i = 0; i < (data.length); i += 1) {
data[i] = randFile.readByte();
}
Does anybody have insight into why this might be?