Byte stream
The most basic unit of byte stream processing in Java is a single byte, which is usually used to process binary data . The two most basic byte stream classes in Java are InputStream
and OutputStream
, which represent the basic input byte stream and output byte stream respectively.
The InputStream class and the OutputStream class are both abstract classes. In actual use, we usually use a series of their subclasses provided in the Java class library.
Online learning video sharing: java learning video
Character stream
The most basic character stream processing in Java A unit is a Unicode code unit (size 2 bytes), which is typically used to process text data. The so-called Unicode code element is a Unicode code unit, ranging from 0x0000~0xFFFF.
Each number in the above range corresponds to a character. By default, the String type in Java encodes characters according to Unicode rules and then stores them in memory. However, unlike storage in memory, data stored on disk usually has various encoding methods. Using different encoding methods, the same characters will have different binary representations.
The difference between character stream and byte stream
After the above description, we can know the main differences between byte stream and character stream The difference is reflected in the following aspects:
1. The basic unit of byte stream operation is byte; the basic unit of character stream operation is Unicode code element.
2. Byte streams do not use buffers by default; character streams use buffers.
3. Byte stream is usually used to process binary data. In fact, it can process any type of data, but it does not support direct writing or reading of Unicode code elements; character stream usually processes text data, which supports Write and read Unicode code units.
Recommended related articles and tutorials: java quick start
The above is the detailed content of The difference between character stream and byte stream in java. For more information, please follow other related articles on the PHP Chinese website!