Reading from Binary Files
Hi, I am trying to write java code to read and write to and from binary files. To write to a file I am using code like this:
public void putUnsignedInt(int input) {
Unsigned.putUnsignedInt ( _buffer, input );
}
public void putUnsignedShort(short input) {
Unsigned.putUnsignedShort( _buffer, input );
}
public void putFloat(float input) {
_buffer.putFloat( input );
}
Where the Unsigned class is from com.ronsoft.books.nio.buffers.Unsigned and _buffer is a ByteBuffer.
My problem is with reading the binary file. I am unable to read the floats or the ints. All I get is garbage values. I tried using the getFloat method of the ByteBuffer, the Unsigned get methods, and even messed around with shift operators, and still nothing. Can you tell me what the proper way is to read from the binary files? Or maybe tell me a method for reading and writing binary files that work together? I have been working on this for hours and I can't get anywhere. Any help would be greatly appreciated.
|