简体   繁体   中英

what's the difference between character stream and byte stream?

first, I know the difference between character and byte. character is a signature or remark of something("A", "中" or other), byte is a concrete size in computer. And the size of a character in computer depends on the encoding style. But what exactly is a character stream and a byte stream? what's the specific type they stand for? A byte stream is a stream of bytes? if so, what is a stream of character? My last question is, what type of stream does TCP transport?

Character Stream is a higher level concept than Byte Stream. A Character Stream is, effectively, a Byte Stream that has been wrapped with logic that allows it to output characters from a specific encoding; as opposed to one having to read bytes and decode the characters they represent.

An InputStream reads bytes, and a Reader reads characters.

Everything over TCP will natively be in bytes. If you know that the byte stream is representing characters, you can use an InputStreamReader to use the InputStream as a Reader.

java中的characterstream类用于处理ex-hadles unicode的字符输入和输出,而字节流类用于处理字节的输入和输出,即ascii代码。前者用于java 1.0版本,后来用于java 1.1

TCP transports bytes of course. What these bytes represent is up to the protocol.

You can read about the relation between character and byte streams here: http://docs.oracle.com/javase/tutorial/i18n/text/stream.html

Practically, a character stream is an application-side abstraction over a byte stream, allowing to read/write bytes into or from characters using various encodings.

Have a look at this :

  1. Character Streams versus Byte Streams
  2. Character and Byte Streams

and i assume TCP transport packets, stream of bytes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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