Skip to main content
edited tags
Link
Taryn
  • 248.9k
  • 57
  • 374
  • 409
Post Undeleted by George Stocker
Post Deleted by Tunaki, Mogsdad, Josh Crozier
Post Closed as "Duplicate" by Tunaki java
edited title
Link
Lesmana
  • 27.3k
  • 12
  • 84
  • 87

java:If Is it is necessorynecessary to close thean InputStreamReader in a parenthesesBufferedReader

Source Link
xialu
  • 304
  • 4
  • 11

java:If it is necessory to close the InputStreamReader in a parentheses

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~