简体   繁体   English

Java字节流和字符流

[英]Java byte streams and character streams

From Java Docs: 从Java Docs:

The Console object also provides input and output streams that are true character streams, through its reader and writer methods. Console对象还通过其reader和writer方法提供了输入和输出流,它们是真实的字符流。

Why should I care if the underlying stream is a byte stream or a character one? 我为什么要关心基础流是字节流还是字符流? I know that in byte stream it read one byte at a time and in character streams it reads a character at a time which can be of many bytes according to the specifics of the machine(? correct me if I'm wrong). 我知道在字节流中它一次读取一个字节,而在字符流中它一次读取一个字符,根据机器的具体情况,该字符可以是许多字节(如果我错了,请纠正我)。

Why should I care if the underlying stream is a byte stream or a character one? 我为什么要关心基础流是字节流还是字符流?

Because bytes are for binary data and characters are for text data. 因为字节用于二进制数据,而字符用于文本数据。 If you read a character like € it will be just one characters even though if you read it a byte at a time it could 3 bytes or not depending on the encoding. 如果您读一个像€的字符,即使您一次读一个字节,它也只能是一个字符,根据编码的不同,一次读一个字节可能是3个字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM