If the question is:BufferedReader is closed, is it necessary to close InputStreamReader and InputStream?, then this problem is normal...
The stream and reader in Java's io package both use the decorator pattern. You only need to call the close method of the outermost decorator, and it will also close the stream or reader it decorates.
If that doesn’t work, open the source code ofBufferedReaderand take a look at the close method. You will find that it closes the reader it decorates in this method.
No matter how hard it is, I recommend the following article, which may be able to solve your doubts "Java IO: Streams, and the application of the decorator pattern on it"
Just call the outermost close() directly
update:
http://docs.oracle.com/javase/8/docs/api/java/io/BufferedReader.html#close--
http://docs.oracle.com/javase/8/docs/api/java/io/InputStreamReader.html#close--
It’s a chain. You close the outermost one, and the outermost one closes the inner ones. The inner ones close the inner ones
Of course, if you insist on saying that the shutdown may fail, you must finally do it. I can’t help it
If the question is:BufferedReader is closed, is it necessary to close InputStreamReader and InputStream?, then this problem is normal...
The stream and reader in Java's io package both use the decorator pattern. You only need to call the close method of the outermost decorator, and it will also close the stream or reader it decorates.
If that doesn’t work, open the source code of
BufferedReader
and take a look at the close method. You will find that it closes the reader it decorates in this method.No matter how hard it is, I recommend the following article, which may be able to solve your doubts "Java IO: Streams, and the application of the decorator pattern on it"
You have to close them all, one by one in order, preferably in finally
The first level created is the last level, the last level created is the first level