workbook循环压缩,最后下载的压缩包只用最后循环的excel文件

CSDN问答 2021-12-30 13:35:19 阅读数:180

循环 压缩 最后 workbook 后下
问题遇到的现象和发生背景

workbook循环压缩,最后下载的压缩包只用最后循环的excel文件

问题相关代码,请勿粘贴截图

ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ZipOutputStream zos = null;

 try { for (String name : workbooks.keySet()) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); zos = new ZipOutputStream(byteArrayOutputStream); Workbook workbook = workbooks.get(name); ZipEntry entry = new ZipEntry(name); zos.putNextEntry(entry); workbook.write(bos); bos.writeTo(zos); zos.closeEntry(); zos.close(); bos.close(); } byte[] bytes = byteArrayOutputStream.toByteArray(); ByteArrayInputStream byteInputStream = new ByteArrayInputStream(bytes);
版权声明:本文为[CSDN问答]所创,转载请带上原文链接,感谢。 https://ask.csdn.net/questions/7613013