The difference between InputStream
and InputStreamReader
is that InputStream
reads as byte
, while InputStreamReader
reads as char
. For example, if the text in a file is abc
,then both of them work fine. But if the text is a你们
, which is composed of an a
and two Chinese characters, then the InputStream
does not work.
So we should use InputStreamReader
, but my question is:
How does InputStreamReader
recognize characters?
a
is one byte, but a Chinese character is two bytes. Does it read a
as one byte and recognize the other of characters as two bytes, or for every character in this text, does the InputStreamReader
read it as two bytes?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…