Do I need to close InputStream after I close the Reader

前端 未结 5 991
面向向阳花
面向向阳花 2020-12-05 16:50

I was wondering, whether is there any need for me to close the InputStream, after I close the reader?

    try {
        inputStream = new java.io.FileInputSt         


        
5条回答
  •  鱼传尺愫
    2020-12-05 17:45

    Acordding to source sniffing the reader closes its underlying inputstream. According to javadoc it seams that InputStreamReader "closes the stream" when reader.close() is invoked.

    I'm not sure if ANY Reader must close its sources when you do reader.close(). I think that this is important so your code can use a reader no matter what concrete type it is.

    Anyway it makes sense that it's enforced.

提交回复
热议问题