java - Is it necessary to close an InputStreamReader in a BufferedReader -


this question has answer here:

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

Popular posts from this blog

php - Admin SDK -- get information about the group -

dns - How To Use Custom Nameserver On Free Cloudflare? -

Python Error - TypeError: input expected at most 1 arguments, got 3 -