Summary of Java I/O streams

Source: Internet
Author: User

Class structure diagram for I/O

Classification of I/O

Depending on the type of data processed: byte stream and character stream.

It is divided into: input stream and output stream according to data flow.

Flow can be divided into node flow and processing flow.

Node stream

Connect directly to the data source

Process Flow

Used in conjunction with the node stream, and then nested one layer on the basis of the node flow. Improve the read efficiency of your files.

Input stream

InputStream

The function is to read the data generated by the data source in the form of bytes.

Reader

The function is to read the data generated by the data source in the form of a character.

Output stream

OutputStream

The function is to write the data in bytes on the receiving end.

Writer

The function is to write the data in the form of a character on the receiving end.

Common streams

Buffered streams

Function: Buffer stream provides buffer, first write the data to buffer, when the buffer is full, then write the contents of the buffer to the file. This will improve read efficiency.

Object Flow

Function: Used to write/read information about an object, making the object persistent.

Precautions for use:

1. If you want to write an object to disk, then the class that the object belongs to must be serialized, implement the Serializable interface, serializable interface is not any method, is a tag interface
2. If the object belongs to the class member variable changes, you read the original object is an error, if you want to resolve the error, ensure that Serialversionuid is unique.
3. If you do not want to save some information to disk, you can use the Transient keyword to modify the member variable
4. If another class is referenced in a class, the other class also implements the Serializable interface.

Pipe flow

Role: Communication between two threads can be performed. One thread as the pipe output stream and the other as the pipeline input stream.

Convert stream

Function: Used for conversion of Byte stream and character stream.

InputStreamReader: Converting a byte stream to a character stream

OutputStreamWriter: Converting a character stream to a byte stream

Summary of Java I/O streams

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.