0

当我为 zipOutputStream 调用 .finish() 和 .close() 以在我的 webApp 页面上下载 zip 文件时,它会将 zip 文件的内容保存在我的临时用户文件夹中(例如:c:/user/appdata/local /temp ) 但我想将此文件保存在 TomcatHome/temp 中。

// setting headers
response.setContentType("application/zip");
response.setStatus(HttpServletResponse.SC_OK);
response.addHeader("Content-Disposition", "attachment; filename=\"test.zip\"");

// creating byteArray stream, make it bufforable and passing this buffor to ZipOutputStream
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(byteArrayOutputStream);
ZipOutputStream zipOutputStream = new ZipOutputStream(bufferedOutputStream);

for (int i = 0; i < listIdFile.size(); i++) {
  try {

    FileDTO file = this.fileDAO.getFileById(listIdFile.get(i));


    File fileFull = this.fileDAO.readFileFull(Integer.parseInt(file.getId()));

    zipOutputStream.putNextEntry(new ZipEntry(file.getNomeFile()));
    FileInputStream fileInputStream = new FileInputStream(fileFull);

    IOUtils.copy(fileInputStream, zipOutputStream);

    fileInputStream.close();
    zipOutputStream.closeEntry();

  } catch (Exception e) {
    log.error(e.getMessage());
    e.printStackTrace();
    // return downloadDocumentoDaLocale(response, listIdFile);

  }
}

if (zipOutputStream != null) {
  // zipOutputStream.finish();

  zipOutputStream.close();
  zipOutputStream.finish();
  IOUtils.closeQuietly(zipOutputStream);
}
IOUtils.closeQuietly(bufferedOutputStream);
IOUtils.closeQuietly(byteArrayOutputStream);

}

有什么建议吗?

谢谢

4

0 回答 0