Java programming ideology-java I/O system and java programming ideology I/O system

Source: Internet
Author: User

Java programming ideology-java I/O system and java programming ideology I/O system

I. What is I/O?

Io is essentially the movement of a single byte, while a stream is the carrier and method of byte movement, which keeps moving data to the target, what we need to do is read data from the stream or write data to the stream based on the stream direction.


Ii. library classes that support IO operations in java

1. There are two types of data:

(1) byte type: InputStream and OutputStream

(2) character types: Writer and Reader

2. There are two types of data flows:

(1) disk-based io Interface: File

(2) network-based io Interface: socket

Iii. Description of io interfaces for byte streams and hidden streams

Byte streams include InputStream and OutputStream. The primary stream includes the input stream Reader,

The following figure shows the classes related to InputStream. Only the first-level subclasses are listed:


InputStream provides some read methods for subclass inheritance to read bytes.

The related classes of OutputStream are shown as follows:


OutputStream provides some write methods for subclass inheritance to write bytes.

The following figure shows the Reader-related classes:


Reader provides some read methods for subclass inheritance to read characters.

The Writer class diagram is as follows:


Writer provides some write methods for subclass inheritance to write characters.

Almost every two-byte stream subclass has a corresponding byte stream subclass. The feature is the same as that of the two. The difference lies in whether the operation is byte or character. For example, CharArrayReader and ByteArrayInputStream both create an Array Buffer in the memory as the input stream. The difference is that the former array is used to store characters and one character is read from the array each time. The latter is for bytes.

ByteArrayInputStream and CharArrayReader Provides the buffer operation function for multi-threaded communication. It is often used to read fixed-length data packets in the network.
ByteArrayOutputStream, CharArrayWriter Provides the buffer operation function for multi-threaded communication. It is often used for one-time writing after receiving data of sufficient length.
FileInputStream, FileReader Write files into memory as input streams to read files
FileOutputStream, FileWriter Write the data in the memory as the output stream into the file to write the file.
StringReader Read String content as input stream
StringWriter Write data to a String
SequenceInputStream Combines data from multiple input streams into one data stream.
PipedInputStream, PipedReader, PipedOutputStream, and PipedWriter Pipeline stream, mainly used to transmit data between two threads
ObjectInputStream The object data is read as the input stream. The transient and static member variables in the object are not read or written.
ObjectOutputStream Write data to an object
FilterInputStream, FilterOutputStream, FilterReader, and FilterWriter The filtering of circulation sources and targets is other input and output streams. You can see that there are many sub-classes that have their own purposes. I will not describe them one by one.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.