We all know that it is a good habit to close all the StreamReaders we have defined at the end of code.
Now we can see that two Readers was defined as below. BufferedReader and InputStreamReader.The BufferedReader was closed, but we are unable to close the InputStreamReader.
JAVA code:
BufferedReader in = new BufferedReader(new InputStreamReader( connection.getInputStream())); if (in != null) { in.close(); } The problem is here, if the InputStreamReader in the parentheses should be closed? Will this kind of code bring some problem to the program? Please tell me , thank you~
BufferedReader#close, you will see it says "Closes the stream and releases any system resources associated with it. Once the stream has been closed, further read(), ready(), mark(), reset(), or skip() invocations will throw an IOException. Closing a previously closed stream has no effect.", which basically means that callingcloseonBufferedReaderwill close any associated (child) streams