Reading BInary Data
I'm having some problems reading binary data from a file. I know that this is the networking part of the forum, but i believe this is very similar from reading binary Data from a network stream and from a file stream...
So my problem is that i have unsigned binary data in my file. So far no problemen because due to this there is the readUnsignedShort() method on the DataInputStream.
I write with a c# programm a file like this:
and i read it in java like this:
using (BinaryWriter bin = new BinaryWriter(File.Open("test.bin",FileMode.Create)))
my results are very confusing:
RandomAccessFile raf = new RandomAccessFile(new File("test.bin"), "r");
can somebody help me?
Could be little vs big endian Endianness - Wikipedia, the free encyclopedia
You might hand check the data in the file and also check for endianess of C# and java.
although i work for a longer time with java, i do not know how to change the endianess of the RandomAccessFile or DataInputStream...
Do i HAVE TO use the ByteBuffer or is there another solution?
Take your file and read it byte by byte, and print each byte, in hex, to the console. Make sure the C# program wrote out what you think it did. That will tell you if you have an "endian" problem. If so, your friend the ByteBuffer can help. Once you get used to it, ByteBuffer is fairly easy to use. Of course, it took me about 10 straight hours to get used to it...