Search code examples
javafilerandom-access

How to read a "long" number of bytes from file with RandomAccessFile in java


I'm trying to read a file, from a certain point in the file for a certain number of bytes.

RandomAccessFile randomAccessFile = new RandomAccessFile(_file, "r"); randomAccessFile.seek(_offSet);
randomAccessFile.read(buffer, 0, _size);

Where the _offSet and _size type is "long".

The problem is, read method only takes "int". I overcame the offset problem by using "seek", how do I overcome the amount of bytes to read?


Solution

  • There is no advantage I can see in trying to read more than 2 GB at once (other than simplicity) You can read more than 2 GB using multiple calls.