cool hit counter [J2SE Fast Forward] - Introduction to IO Streams_Intefrankly

[J2SE Fast Forward] - Introduction to IO Streams


Copyright: This is an original post by the blogger and may not be reproduced without the blogger's permission. https://blog.csdn.net/huyuyang6688/article/details/43762149

The concept of IO flow

IO flow is an abstraction of data flowing from one place to another, like water flowing from one end of a pipe to the other. In a program, all data is transferred and saved as a stream.

All of the stream classes provided by the JDK are located in the java.io package, and they all inherit from each of the following four abstract stream classes: InputStream, OutputStream, Reader, and Writer.

Description.

InputStream: streams that inherit from InputStream are used to input data into the program, and all data units are bytes (8 bits). OutputStream:inherited fromOutputStream The streams are all used by the program to output data to the outside, and the data units are all bytes(8 location)。 Reader:inherited fromReader The streams are all used to input data into the program, and the data units are all characters(16 location)。 Writer:inherited fromWriter The streams are all used by the program to output data to the outside, and the data units are all characters(16 location)。

Classification of IO streams

★ Classified by flow direction, IO flow's can be classified as input stream harmony output stream . In general, the input and output of data are considered from the program's point of view, so the input stream is when the program reads data from the file, i.e., the data flows from the file to the program; the output stream is when the data is made to flow from the program to the file.

★ press transmission unit come to a classification,IO Streams can be divided into byte stream harmony character stream . As the name implies, byte streams transfer data in bytes as the basic unit, and character streams transfer data in Unicode characters that occupy 2 bytes as the basic unit. That said, recall the basics by the way: 1Byte(byte) = 8bit(bit), because characters in Java are encoded in Unicode, each character takes up two bytes, and the storage space occupied by each basic data type in Java is.

types

Storage space occupied

char

2 bytes

byte

1 byte

short

2 bytes

int

4 bytes

long

8 bytes

float

4 bytes

double

8 bytes

byte stream Can be used for any types object of, Includes binary objects, but (not) character stream Can only handle characters or strings; 2. byte stream Provides the ability to handle any types ofIO Function of operation, But it can't handle directlyUnicode word-symbol, but (not) character stream will be able to。

When it is understood that by flow harmony transmission unit When these two classifications are made, they can be viewed in combination with that mind map above.

Reader harmonyInputStream all belong input stream, Their subclasses are responsible for reading data from the data source;Writer harmonyOutputStream all belong output stream, Their subclasses are responsible for writing data to the specified location。

Reader and Writer both belong to character streams, and their subclasses both transfer data in characters as the basic unit; InputStream and OutputStream both belong to byte streams, and their subclasses both transfer data in bytes as the basic unit.

★ It is also possible to make a decision based on IO Classification by function of the stream, subdivide nodal flow harmony processing flow . A node stream reads and writes data from or to a particular node; a processing stream is a concatenation and encapsulation of an already existing stream, and can be seen as an optimization or filtering of an already existing stream.

The following mind map is expanded to look at the vast IO family in java.

Here is a global understanding of the IO mechanism in java first, followed by further study and summary of these four abstract classes and their subclasses.


Recommended>>
1、Academic Understanding selfencoders and their uses in one article with code examples
2、ansible service deployment and use
3、How to improve your abilities a few tips for young programmers experience from the big boys
4、Docker learning of building JavaWeb environment advanced chapter
5、An article detailing common monitoring tools for Linux systems forward mail

    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号