views:

556

answers:

2
+1  A: 

Don't use String/char when handling binary data. Use byte[]/byte instead. Fix that before you try to fix any other bugs.

char is a 16-bit value in Java, it's not the same as the C char (which is defined to be a byte). The closest thing to a C char in Java is the byte (which is signed, 'though).

Joachim Sauer
+1  A: 

You're comparing bytes with Strings - this is a Bad Thing, as you dont know what encoding Java is using to cnvert a given byte into a textual representation.

Use a ByteBuffer and do comparisons between raw bytes as they are read.

Visage