Home  >  Article  >  Java  >  The difference between java byte stream and character stream

The difference between java byte stream and character stream

(*-*)浩
(*-*)浩Original
2019-12-26 11:44:443449browse

The difference between java byte stream and character stream

#What is a byte stream in java?

Byte stream in Java helps to perform input and output operations of 8-bit bytes; it ends with stream. In other words, it processes data byte by byte and is suitable for processing raw data such as binary files. (Recommended learning: java course )

The most commonly used class of byte flow operations are FileInputStream and FileoutPutStream. FileInputStream helps in reading from the source while FileOutputStream helps in writing to the destination.

What is a character stream in java?

In java, characters are stored using the Unicode convention. The character stream automatically allows us to read/write data character by character, helping to perform 16-bit Unicode input and output; it ends with a reader and a writer.

The most common classes of character streams in Java are FileReader and FileWriter. Internally, FileReader uses FileInputStream; similarly, FileWrite uses FileOutputStream.

The difference between byte stream and character stream in Java

Byte stream is a mechanism that performs 8-bit byte input and output. The basic unit is a byte; the character stream is a mechanism for performing 16-bit Unicode input and output operations in Java, and the basic unit is a Unicode code element.

The byte stream ends with stream; and the character stream ends with reader and writer

The byte stream is the most basic, using ASCII Encoding; it is usually used to process binary data, which is processed by bytes. In fact, it can process any type of data, but it does not support direct writing or reading of Unicode code elements.

The character stream uses Unicode encoding, which is processed according to the virtual machine's encode, that is, the character set is converted; it usually processes text data, and it supports writing and reading Unicode code element.

Byte streams do not use buffers by default; character streams use buffers.

The above is the detailed content of The difference between java byte stream and character stream. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn