I have two examples :
Example 1:
try (ByteArrayOutputStream baous = new ByteArrayOutputStream();
FileOutputStream fouscrx = new FileOutputSt
Well, it looks like the try-with-resources autoclosing order is important, and the ZipOutputStream has to be closed first when unwinding things. Autoclosing happens in reverse order of their creation in this context.
What happens if you reorder your second example so the ZipOutputStream is after the FileOutputStream? (Though placing the ZipOutputStream in its own try-catch block is clearer code if you ask me. We separate out the related and unrelated streams and handle the auto-closing in an easily readable manner.)
UPDATE
FWIW, this is the sort of idiom I have used in the past when streaming a zip into a buffered output stream:
try (final ZipOutputStream zip = new ZipOutputStream(new BufferedOutputStream(
new FileOutputStream(zipFile.toString())))) { ... }