IO overview of Java IO stream


IO stream overview


In the program, all the data are transmitted and saved in the form of stream, and the program reads the data through the input stream; When the program needs to save some data for a long time, use the output stream to complete.

The essence of IO stream:

Data transmission between local devices and different devices, such as local file copy, upload file and download file, etc.

be careful:

1. All operations on data are carried out by Java through streams

2. The input and output of the program are saved in the form of stream, and all the files saved in the stream are byte files.

3. IO stream can achieve data persistence, but IO stream is essentially used to deal with file system and data transmission between different devices.

Classification of IO streams:

There are two different ways of classification

According to the direction of data transmission:

1. Input stream: read data from outside (keyboard, network, file, etc.) to memory

2. Output stream: used to write the data in the program to the outside world (display, file…)

According to the type of data transmitted:

1. Byte stream: generally for binary files [video, audio, picture]

2. Character stream: generally for text files [XML, JSON, HTML, TXT, MD…]

**There are three elements of flow operation

1. Data source: where does the data come from( Memory can be used as a destination or a transfer station)

2. Destination: where does the data go( Memory can be used as a destination or a transfer station)

3. Means of transportation:

a. Choose the type of convection, input stream or output stream, or both

b. Select the most suitable flow in io flow frame according to the determined flow direction

Difference between byte stream and character stream:

1. Different reading and writing units: byte stream is in byte (8bit) unit, character stream is in character unit, according to the code table mapping characters, it may read more than one byte at a time.

2. Different processing objects: byte stream can process all types of data (such as pictures, avi, etc.), while character stream can only process character type data. For example: document, JSON, HTML, CSS, JS, XML

Note: as long as you are dealing with plain text data, you should give priority to the use of character stream. In addition, you should use byte stream

IO stream inheritance architecture diagram:

IO overview of Java IO stream

This work adoptsCC agreementReprint must indicate the author and the link of this article

Recommended Today

Large scale distributed storage system: Principle Analysis and architecture practice.pdf

Focus on “Java back end technology stack” Reply to “interview” for full interview information Distributed storage system, which stores data in multiple independent devices. Traditional network storage system uses centralized storage server to store all data. Storage server becomes the bottleneck of system performance and the focus of reliability and security, which can not meet […]