Java Io Stream Analysis

Source: Internet
Author: User
Tags object serialization

Streams in Java can be classified from different perspectives.

Different data streams can be divided into input streams and output streams.

Data processing units can be divided into byte streams and batch streams.

Different implementation functions can be divided into node stream and processing stream.

 

Output stream:

 

Input stream:

Therefore, both input and output are from the program perspective.

Byte stream: an 8-bit binary data is read or read at a time.

Bytes stream: A 16-bit binary data is read or read at a time.

The principle of byte stream and byte stream is the same, but the processing unit is different. The suffix is stream, which is a byte stream, the suffix is reader, and writer is a bytes stream.

 

Node stream: directly connected to the data source, read or read.

It is inconvenient to directly use the node stream to read and write files. In order to read and write files faster, the stream can be processed.

Stream processing: It is used together with the node stream. Based on the node stream, it is connected to another layer.

The streams provided by JDK inherit four categories: inputstream (byte input stream), outputstream (byte output stream), reader (character input stream), and writer (character output stream ).

The following streams are commonly used in Java I/O.

 

Byte input stream:

Byte output stream:

Character input stream:

Character output stream:

Brief Introduction:

File Operations: fileinputstream (byte input stream), fileoutputstream (byte output stream), filereader (character input stream), filewriter (character output stream)

Operations on pipelines: pipedinputstream (byte input stream), pipedoutstream (byte output stream), pipedreader (character input stream), and pipedwriter (character output stream)

An instance of pipedinputstream must be used together with an instance of pipedoutputstream to complete read and write operations on the pipeline. It is mainly used for thread operations.

Bytearrayinputstream, bytearrayoutputstream, chararrayreader, and chararraywriter are a byte or character array in the memory.

Buffered buffer streams: bufferedinputstream, bufferedoutputstream, bufferedreader, and bufferedwriter are processing streams with buffers. The main purpose of the buffer zone is to avoid dealing with hard disks every time and improve data access efficiency.

Conversion stream: inputstreamreader/outputstreamwriter converts bytes into characters.

Data Stream: datainputstream and dataoutputstream.

Because if we output an 8-byte long type or 4-byte float type, what should we do? You can output data in one byte or one byte, or convert it to a string. However, if the conversion is time-consuming, it would be nice to directly output data. Therefore, this data stream solves the difficulty of outputting data types. Data streams can directly output the float or long type, improving the efficiency of data read/write.

Print stream: printstream, printwriter, which is usually printed on the console and can be controlled and printed.

Object stream: objectinputstream and objectoutputstream, which directly outputs encapsulated objects instead of converting them into strings and then outputting them.

Serialized stream: sequenceinputstream.

Object serialization: directly converts an object to binary and writes it to the media.

To use object streams, you must implement the serializable interface. Otherwise, an error is returned. If the transient keyword is used to modify the member variable, this member variable is not written. If the reference type member variable is null, the value type member variable is 0.

Related Article

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.