Dave Eland wrote:
It appears that the data I/O methods for the RandomAccessFile class
(e.g. readInt() and writeInt()) handle data in "big endian format"
(most significant byte first). If you have a file where the data was
written in "little endian format" (least significant byte first" how
is the best way to read that data in Java?
Dave Eland
da******@oru.edu
Look at ByteBuffer & company. Something like this:
RandomAccessFile file = new RandomAccessFile(filename, "r");
byte[] recordBuffer = new byte[RECORD_LENGTH];
ByteBuffer record = ByteBuffer.wrap(recordBuffer);
record.order(ByteOrder.BIG_ENDIAN);
FloatBuffer floatRecordBuffer = record.asFloatBuffer();
IntBuffer intRecordBuffer = record.asIntBuffer();
Use
file.seek(offset);
file.read(recordBuffer);
to read the file, and
intRecordBuffer.rewind();
intRecordBuffer.get(arrayOfInts, offset, sizeOfArray);
to get it into your arrayOfInts.