In the current code you are using the try-with-resources statement, so your ZipFile docsZip
is closed as soon as the try
is completed.
When you put the declaration of docsZip
within the try
it will not be closed (note that this should then be done somewhere after out.close()
.