Why do I have to close the ZipOutputStream in a certain way in this situation?

后端 未结 2 1111
無奈伤痛
無奈伤痛 2021-01-07 02:09

I have two examples :

Example 1:

try (ByteArrayOutputStream baous = new ByteArrayOutputStream();     
    FileOutputStream fouscrx = new FileOutputSt         


        
2条回答
  •  灰色年华
    2021-01-07 02:20

    ZipOutputStream has to do several operations at the end of the stream to finish the zip file, so it's necessary for it to be closed properly. (Generally speaking, pretty much every stream should be closed properly, just as good practice.)

提交回复
热议问题