J2SE Fast Advanced--io Flow

Source: Internet
Author: User

The concept of Io stream

An IO stream is an abstraction that flows from one point of data to another, as if the water flowed from the end of the pipe to the other end. In the program, all the data is transmitted and saved in a stream way.   

All of the flow classes provided by the JDK are in the java.io package, and these classes inherit from the following four abstract stream classes: InputStream, OutputStream, reader, and writer.

Description

InputStream: Streams that inherit from InputStream are used to enter data into the program, and the Data units are bytes (8-bit).
OutputStream: Streams that inherit from OutputStream are programs that output data outward, and the data units are bytes (8-bit).
Reader: Streams that inherit from reader are used to enter data into the program, and the data units are characters (16 bits).
Writer: streams that inherit from writer are programs that output data outward, and the data units are characters (16 bits).


Classification of IO streams

★ Classify by Flow direction,IO stream can be divided into input stream and output stream . in general, the input and output of the data are from program point of view, so the input stream is the program to read data from a file, that is, the data flow from the file to the program; the output stream is the flow of data from the program to the file.

★ According to the transmission Unit classification, IO Stream can be divided into byte streams and character stream. As the name implies, the byte stream transmits the data in bytes as the basic unit, and the character stream transmits the data in a 2-byte Unicode character as the basic unit. Speaking of which, by the way, recall the basics: 1Byte (bytes) =8bit (bits) because characters in Java are Unicode encoded, so each character occupies two bytes, and the basic data types in Java occupy the storage space:

2  bytes
type takes up storage
char 2  bytes
byte 1 bytes
short
int 4  bytes
long 8&nbs p; byte
float 4 bytes
double 8 bytes

Byte streams can be used for any type of object, including binary objects, whereas character streams only handle characters or strings; 2. The byte stream provides the ability to handle any type of IO operation, but it cannot handle Unicode characters directly, and a character stream is available.

When you understand the two classifications by flow direction and transmission Unit , you can combine the mind map above to see:

Both reader and inputstream are input streams, and their subclasses are responsible for reading data from the data source; writer and outputstream belong to the output stream, and their subclasses are responsible for writing the data to the specified location.

Both reader and writer are character streams, and their subclasses transmit data in the basic unit of characters, and both InputStream and OutputStream are byte streams, and their subclasses transmit data in bytes as basic units.

            

★ also can be classified according to the function of Io stream, divided into node stream and processing stream . A node stream reads and writes data from or to a specific node, and the processing stream is a connection and encapsulation of a stream that already exists, which can be seen as an optimization or filtering of an already existing stream.



Here's a look at the huge IO family in Java:

First, there is a global understanding of the IO mechanism in Java, which will be followed by further learning and summarizing the four abstract classes and their subclasses.

J2SE Fast Advanced--io Flow

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.