I just want to point out a small bug in the above code:
Having "sheets" File:s being temp files inhibited med to File.delete() those due to "zip" not being closed. Adding the "zip.close()" sovled this problem.
Thanks for pointing out that bug it may help someone else in the future.
To improve that code further wherever streams are used they should be wrapped in a try-catch clause with the close() done in a finally clause to ensure it is always called.
Don't worry about correcting errors, that's how we all learn to be better programmers. Just remember to be nice when doing so.
BTW In your code, zos.close() could throw an exception which would mean zip.close() was never called.
You don't show it but I assume you have also added try-catch-finally clauses to the input streams.
BTW In your code, zos.close() could throw an exception which would mean zip.close() was never called.
Oh (beeep)! You are of course right, and no, you assumed wrong! But I've fixed it and it now it looks like this:
I let all IOExceptions be thrown uppward where they eventually will be handled and logged. I don't think it is a good idea to swallow them on failed close() just because you are done for the moment since if this happens there is obvously something wrong.
One interesting (and non relevant :-)) question here is if both close() statements throw an IOException, which will be delivered ? I guess the second one.
One interesting (and non relevant :-)) question here is if both close() statements throw an IOException, which will be delivered ? I guess the second one.