java - Is it necessary to close an InputStreamReader in a BufferedReader -
this question has answer here:
- closing inputstreams in java 6 answers
we know habit close streamreaders have defined @ end of code.
now can see two readers defined below. bufferedreader , inputstreamreader.the bufferedreader closed, unable close inputstreamreader.
java code:
bufferedreader in = new bufferedreader(new inputstreamreader( connection.getinputstream())); if (in != null) { in.close(); }
the problem here, if inputstreamreader in parentheses should closed? kind of code bring problem program? please tell me , thank you~
there no problem doing this, in fact inputstreamreader
documentation java api it.
in case, inputstreamreader
being used bufferedreader
, means both close when bufferedreader
close()
function called it: "closes stream , releases system resources associated it." inputstreamreader
"associated" stream, closed.
when build bufferedreader
using inputstreamreader
way, same reader bundled together, not 2 different readers.
Comments
Post a Comment