1 回答
Why is that and why it doesn't print english ASCII symbols out?
From DataInput.readChar()
:
Reads two input bytes and returns a char value. Let a be the first byte read and b be the second byte. The value returned is:
(char)((a << 8) | (b & 0xff))
This method is suitable for reading bytes written by the writeChar method of interface DataOutput.
In other words, it's treating your file as if it's UTF-16-encoded - and it almost certainly isn't.
When you want to read text data you should use a Reader
subclass, e.g. InputStreamReader
wrapped around FileInputStream
, specifying the appropriate encoding for the input data.