when i call .finish() and .close() for a zipOutputStream for download a zip file on a page of my webApp, it saves the content of zip file in my temp user folder ( example: c:/user/appdata/local/temp ) but i want to save this files in 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);
}
Any suggest?
Thank you