I am reading a binary file (that was written in c#) in java. its a long file more than 360Kb. I have to read the code byte by byte to populate the fields.
we have reading code already implemented in c# and have to replicate the behavior. In c# the code is something like this
FileVersion = s.ReadByte()
FileVersionMinor = s.ReadByte()
HeaderLength = s.ReadInt16()
Now I am trying to do same as above in java
dis = new DataInputStream(fin);
fileVersionMajor = dis.readUnsignedByte()
def fileVersionMinor = dis.readUnsignedByte()
def headerLength = dis.readShort()
but I get different output, when i tried to drill down the issue, I see that java code appends 00000000 at the end of streambyte.
Whats the issue here?
PS if I do
def headerLength = dis.readByte(),
I get expected value.
Talk1:
There is no def keyword as C#'s var in Java, maybe you mean Scala (requires retag to [scala])?
Solutions1
You probably need to use readByte() instead of readUnsignedByte().
Talk1:
you are wrong, ReadByte() gives the unsigned int so as readUnsignedByte()