Closing inputstreams

Posted by Nick on Stack Overflow See other posts from Stack Overflow or by Nick
Published on 2010-06-12T15:23:26Z Indexed on 2010/06/12 15:33 UTC
Read the original article Hit count: 259

Filed under:
|
|

I have the below code to read from a URL object:

URL url= new URL("http://datasource.com");     
BufferedReader reader = new BufferedReader(
                                new InputStreamReader(url.openStream()));

After I am done getting the data, is this sufficient to close and release all the resrouces:

reader.close();

I did not see a method for URL to close it, like URL.close()...but wondering if I shouldn't do something more like this:

InputStreamReader inputStreamReader = new InputStreamReader(url.openStream());
BufferedReader reader = new BufferedReader(inputStreamReader);
// Do Stuff
inputStreamReader.close();
reader.close();

© Stack Overflow or respective owner

Related posts about android

Related posts about url