I have to read and write Multiple excel files with POI and use ZipOutputStream to download. The code below archives file in D disk, but how do I use Apache POI to create and write excel files then archive it by ZipOutputStream?
public void zipFiles(HttpServletResponse response, Workbook workbook, String fileName) throws IOException {
response.setStatus(HttpServletResponse.SC_OK);
response.addHeader("Content-Disposition", "attachment; filename=\""+ fileName +".zip\"");
ZipOutputStream zipOutputStream = new ZipOutputStream(response.getOutputStream());
// create a list to add files to be zipped
ArrayList<File> files = new ArrayList<>(2);
files.add(new File("D://兵庫_WEB申請書.xls"));
files.add(new File("D://兵庫_取消申請書.xls"));
// package files
for (File file : files) {
zipOutputStream.putNextEntry(new ZipEntry(file.getName()));
FileInputStream fileInputStream = new FileInputStream(file);
IOUtils.copy(fileInputStream, zipOutputStream);
fileInputStream.close();
zipOutputStream.closeEntry();
}
zipOutputStream.close();
}