Specific examples of reading and writing Java IO stream files

introduction:

The operation of Java IO stream is very common. It is basically used in every project. Every time you encounter it, you just go to the Internet to find it. It has been tried repeatedly. Last time, a colleague suddenly asked me about reading java files. I was stunned. My first reaction was to go online to find them. Although I could find them, I always felt that I was not very down-to-earth. So I took the time to see some operations of Java IO stream today. I felt very fruitful. By the way, I summarized some materials to facilitate further learning in the future

Classification of IO streams: 1. According to the data objects of streams: high-end streams: all streams in memory are high-end streams, such as inputstreamreader low-end streams: all streams in external devices are low-end streams, such as InputStream. How to distinguish OutputStream: all stream objects whose suffixes include reader or writer are high-end streams, otherwise, It is basically a low-end stream, but there are exceptions. For example, printstream is a high-end stream

2. According to the flow direction of data: output stream: it is used to write data, which is input by the program (memory) - > external device: it is used to read data, which is distinguished by the external device -- > program (memory): Generally speaking, the input stream has input and the output stream has output

3. It is divided according to the format of stream data: byte stream: the stream that processes binary data such as sound or picture, such as InputStream character stream: the stream that processes text data (such as TXT file). For example, how to distinguish inputstreamreader: it can be distinguished by high-end and low-end streams. All low-end streams are byte streams and all high-end streams are character streams

4. According to the packaging process of stream data: original stream: a stream that does not need to pass in another stream as the parameter of its own construction method in the process of instantiating the object of the stream is called original stream. Wrapper flow: in the process of instantiating the object of the flow, another flow needs to be passed in as the flow with parameters issued by its own construction method, which is called wrapper flow. How to distinguish: all low-end streams are original streams, and all high-end streams are packaging streams

Inheritance relationship of IO stream object (as shown below):

Here are some specific code examples:

Read files by bytes

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>