嗨,我上传了MSExcel2007,经过评估,我将多个XSSFWorkbook压缩到一个zip文件中。在将工作簿写入文件时,它隐式关闭outputstream,但我希望在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();
暂无答案!
目前还没有任何答案,快来回答吧!