Closing inputstreams in Java

前端 未结 6 1081
眼角桃花
眼角桃花 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条回答
  •  Happy的楠姐
    2020-12-03 14:10

    I would close all of them in the inverse order from which you have opened them, as if when opening them would push the reader to a stack and closing would pop the reader from the stack.

    In the end, after closing all, the "reader stack" must be empty.

提交回复
热议问题