Question

I'm trying to read the binary content of a text file (which contains the compressed version of a different text file). The first two characters (01111011 and 00100110) are correct (going by the values that were original put there during the compression process.

However, when it gets to the third character, it should be reading 10010111 (again, going by what was added during the compression process), but instead it reads 10000000010100 (aka 8212). Does anyone know what is causing this discrepancy, or how to fix it? Thanks!

Was it helpful?

Solution

The Java FileReader should not be used to read binary data from files since it reads a character at a time using the default encoding (which is most likely not very good for binary reading)

Instead, use FileInputStream which has read methods that reads actual raw bytes without any encoding applied.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top