Our last article spoke of InputStream (input stream). There are two kinds of flows in the input stream: node flow and filter stream. Let's talk about this in this article.
Review what is node flow: The node flow is directly interacting with the target.
Filter Flow: It is directly interacting with the node stream.
The InputStream node streams and filters are as follows:
Explain the above picture: there are so many subcategories for Inutstream. Where FilterInputStream (his sub-class datainputstream,bufferedinputstream .... are filtered streams) are filter streams, others are node streams.
Let's talk about the output stream (OutputStream), let's look at his level:
The same filteroutputstream (and his sub-class Dataoutstream,buffereoutstream is the filter stream) is the filter stream. The others are node streams,
The following two images complement the filter flow:
Let's talk about the Bufferedoutputstream filter flow in OutputStream:
This is for buffering. He is a filter stream that cannot be dealt directly with the IO device, he is the wrapper node stream. That is, the class is content from the program to the file. Without buffering, we have to enter this byte into a file whenever we have a byte, so the consequence is that we will be dealing with the IO device very often, which is very inefficient. So we use buffers, only when a certain number, such as 50 bytes to deal with the IO device, so as to avoid frequent contact with the IO device, improve efficiency.
Let's take a look at its constructor:
See no, it inside the constructor directly with OutputStream, not with what file deal with, that he is filtering flow, play the role of packaging.
The cases are as follows:
public class Filetest { static void main (string[] args) throws IOException { /* * with the function of the cache and the function of the output * */ OutputS Tream os =new FileOutputStream ("1.txt" ) ; Bufferedoutputstream bufferedoutputstream =new Bufferedoutputstream (OS); Bufferedoutputstream.write ( "aaaaaaaa" .getbytes ()); Bufferedoutputstream.close ();}}
03JavaIO detailed _io stream and filter flow in flow classification