XSSFWorkbook写方法隐式关闭输出

时间:2014-03-11 09:41:51

标签: java servlets apache-poi xssf zipoutputstream

您好我正在上传msexcel 2007并在评估之后我将多个XSSFWorkbooks压缩到一个zip文件中。在将我的工作簿写入文件时,它隐式关闭outputsteam但我希望在zip文件中创建更多条目。在ZipOutputStream的调用方法closeEntry中抛出异常java.io.IOException:Stream closed.This is my code

        // 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();

0 个答案:

没有答案