The difference between a byte stream and a character stream

Source: Internet
Author: User
To output one piece of binary data to a device, or to read one piece of binary data from a device,
Whatever input is, we're going to do it in a uniform way, in an abstract way,
This abstract description is named IO stream, the corresponding abstract class is OutputStream and InputStream,
Different implementation classes represent different input and output devices, all of which operate on bytes. In the application, often to be completely character of a piece of text to be sent out or read in, with a byte stream can it?
Everything in the computer ends up being binary bytes. For "China" these characters,
The first thing to do is to get its corresponding byte, and then write the bytes to the output stream. Read, the first read is the byte, but we want to display it as a character, we need to convert the bytes into characters.
Because of such a wide range of needs, people specifically provide a character stream of packaging classes. The underlying device always accepts only byte data, sometimes writing strings to the underlying device,
You need to convert the string to bytes before writing. The character stream is a byte-stream wrapper,
The character stream is directly accepting the string, which internally converts the strings into bytes and then writes to the underlying device.
This gives us a little bit of convenience in writing or reading strings to IO. character to byte conversion, pay attention to the problem of coding, because the string into a byte array, is actually converted to the character of some kind of encoded byte form, reading is the opposite of the truth

The difference between a byte stream and a character stream

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.