来自 Java 文档:
The Console object also provides input and output streams that are true character streams, through its reader and writer methods.
为什么我应该关心底层流是字节流还是字符流?我知道在字节流中它一次读取一个字节,在字符流中它一次读取一个字符,根据机器的具体情况,该字符可以是多个字节(?如果我错了,请纠正我)。
最佳答案
Why should I care if the underlying stream is a byte stream or a character one?
因为字节用于二进制数据,字符用于文本数据。如果您读取像 € 这样的字符,它只会是一个字符,即使您一次读取一个字节,它也可能是 3 个字节,具体取决于编码。
关于Java字节流和字符流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32724222/