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