Byte stream and character stream in Java

Source: Internet
Author: User

@1: Byte stream:
Java.io.InputStream:
Public abstract class InputStream
This abstract class was the superclass of all classes representing an input stream of bytes.

Java.io.OutputStream:
Public abstract class OutputStream
This abstract class was the superclass of all classes representing an output stream of bytes.

InputStream is the ancestor of all byte input streams, and OutputStream is the ancestor of all byte output streams.

@2: Character Stream:
Java.io.Reader:
Public abstract class Reader
Abstract class for reading character streams.

Java.io.Writer:
Public abstract class Writer
Abstract class for writing to character streams.

Reader is the ancestor of all read string input streams, while writer is the ancestor of all output strings.

Inputstream,outputstream,reader,writer are abstract classes. So you can't go straight to new.

@3: Comparison:

The character stream uses buffers, and the byte streams do not use buffers. For validation and code samples that use buffers, you can see here.

Q: Is it good to use a byte stream or a good character flow?
A: Using A byte stream is better.

All files are carried out in bytes on the hard drive or in the transmission, including pictures, etc., which are stored in bytes, and characters are only formed in memory , so

In the development, the use of byte stream is more extensive.

Many other streams have also appeared in the java.io, mainly to improve performance and ease of use.

Byte stream and character stream in Java

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.