嗨,我正在上传 msexcel 2007,经过评估后,我将多个 XSSFWorkbook 压缩到一个 zip 文件中。在将我的工作簿写入文件时,它会隐式关闭 outputteam,但我希望在 zip 文件中创建更多条目。在调用 ZipOutputStream 的方法 closeEntry 时,它会抛出异常 java.io.IOException: Stream closed。这是我的代码
// offer the user the option of opening or downloading the
// resulting Excel file
// Create the ZIP file
String outFilename = "review.zip";
response.setContentType("application/zip");
response.setHeader("Content-Disposition",
"attachment; filename=" + outFilename);
List items = upload.parseRequest(request);
Iterator iterator = items.iterator();
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
outFilename));
while (iterator.hasNext()) {
FileItem item = (FileItem) iterator.next();
if (!item.isFormField()) {
String fileName = item.getName();
System.out.println("filename:- " + fileName);
XSSFWorkbook workbook = Test.review(fileName,
(FileInputStream) item.getInputStream());
out.putNextEntry(new ZipEntry(fileName));
workbook.write(out);// This part is closing output stream implicitly
// Close the entry
out.closeEntry();// This part is throwing exception
}
}
out.close();
out.finish();