Differences between byte stream and byte stream in Java Io

Source: Internet
Author: User

Fileoutstream, fileinputstream, filereader, and fileewiter are often used to learn Java Io streams.

 

Generally, the byte stream is used to read Chinese characters, because a Chinese character is regarded as a character in the byte stream.

 

A stream is an ordered byte sequence that can be used as an input source or an output destination.
The byte stream is input and output in bytes. The byte stream class name contains stream. The byte stream is input and output in characters.
The class name contains reader or writer. For the sake of universality, the characters in Java are 16-bit Unicode characters, so the 8-bit byte stream is required
It must be converted to a 16-bit batch stream. To convert byte streams to bytes streams, use the inputstreamreader class:
Public inputstreamreader (inputstream in );
Public inputstreamreader (inputstream in, string encoding );
Public ouputstreamwriter (onputstream in );
Public onputstreamwriter (onputstream in, string encoding );

The reader and writer classes allow users to seamlessly support international character sets in programs. If the files to be read are from other languages,
Use the batch stream.
Javai/o byte stream and NLP stream are Java-based input/output data. The byte stream is the input/output data of one byte and one byte (two bytes constitute one Chinese character) therefore, garbled characters may occur when reading a string of Chinese characters through word throttling,
In the same way, a text stream is a single character and a text stream (one character = two bytes). You can use a text stream to read a string of Chinese characters to solve garbled characters.

 

The main difference between byte stream and byte stream is their processing method.
Byte streams are the most basic. All inputstream and outputstream subclasses are used to process binary data. They are processed by byte.
However, in reality, a lot of data is text, and the concept of character stream is proposed. It is processed by the encode of the virtual machine, that is, Character Set conversion.
The two are associated through inputstreamreader and outputstreamwriter. In fact, they are associated through byte [] and string.
In actual development, the Chinese character problems are actually caused by inconsistent conversion between the primary stream and the word throttling.

When the bytes are converted to bytes streams, the bytes [] is actually converted to strings,
Public String (byte bytes [], string charsetname)
There is a key parameter character set encoding, which is usually omitted. Then the system uses the Lang of the operating system.
When the bytes stream is actually converted into byte,
Byte [] string. getbytes (string charsetname)
The same is true.

 

According to kilojin, the transmission efficiency of a compaction stream is higher than that of a word throttling.

 

 

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.