Closing inputstreams in Java

前端 未结 6 1074
眼角桃花
眼角桃花 2020-12-03 13:19

I have the following piece of code in a try/catch block

 InputStream inputstream = conn.getInputStream();
 InputStreamReader inputstreamreader = new  InputSt         


        
6条回答
  •  一整个雨季
    2020-12-03 14:09

    By convention, wrapper streams (which wrap existing streams) close the underlying stream when they are closed, so only have to close bufferedreader in your example. Also, it is usually harmless to close an already closed stream, so closing all 3 streams won't hurt.

提交回复
热议问题