Is it necessary to close each nested OutputStream and Writer separately?

后端 未结 7 2070
醉酒成梦
醉酒成梦 2020-11-28 02:28

I am writing a piece of code:

OutputStream outputStream = new FileOutputStream(createdFile);
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputS         


        
7条回答
  •  暖寄归人
    2020-11-28 03:19

    In Java 7, there is a feature try-with-resources. You no need to explicitly close your streams, it will take care of that.

提交回复
热议问题