Java programming idea--java IO system

Source: Internet
Author: User

First, what is IO

IO is essentially a single byte movement, and the stream can be said to be the carrier and way of the byte movement, it keeps moving the data to the target, all we have to do is to read the data from the stream in the direction of the stream or write the data to the stream.


Second, the Java support IO operation of the library class

1, according to the data types are divided into two categories:

(1) Byte type: InputStream and OutputStream

(2) Character type: writer and reader

2, according to the flow direction of data, mainly divided into two categories:

(1) disk operation-based IO interface: File

(2) network-based IO interface: Socket

description of Io interface for byte stream and character stream

The byte stream includes the input stream InputStream and the output stream outputstream. The character stream includes the input stream reader,

The InputStream related class diagram is as follows, listing only one class of subclasses:


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

The OutputStream related class diagram is as follows:


OutputStream provides some write methods for subclass inheritance, which are used to write bytes.

The reader related class diagram is as follows:


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

Writer related class diagram is as follows:


Writer provides some write methods for subclass inheritance, which are used to write characters.

There is almost always a corresponding byte stream subclass for each character stream subclass, with the same function, the difference is only in the operation of bytes or characters. For example, CharArrayReader and Bytearrayinputstream, both create an array buffer in memory as an input stream, except that the array is used to hold characters, one character at a time from the array, and the latter for bytes.

Bytearrayinputstream, CharArrayReader Provides a buffer operation function for multi-threaded communication. Often used to read fixed-length packets in a network
Bytearrayoutputstream, Chararraywriter Provides a buffer operation function for multi-threaded communication. Often used to receive data of sufficient length to write once
FileInputStream, FileReader Write file to memory as input stream, implement read operation to file
FileOutputStream, FileWriter Writes the data in memory as an output stream to the file, enabling write operations to the file
StringReader Reads the contents of a string as an input stream
StringWriter Writes data to a string
Sequenceinputstream Merging data from multiple input streams into one data stream
PipedInputStream, Pipedreader, PipedOutputStream, PipedWriter Pipe flow, mainly used to transfer data between 2 threads
ObjectInputStream Reads the object data as an input stream, and member variables of the transient and static types in the object are not read or written
ObjectOutputStream Writing data to an object
FilterInputStream, Filteroutputstream, FilterReader, Filterwriter Filter flow Changyuan and target is other input and output stream, we can see there are many sub-categories, each has a purpose, do not introduce

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Java programming idea--java IO system

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.