@RequestMapping(value = "downloadZip")
@ResponseBody
public void downloadZip(HttpServletResponse response) throws Exception {
String fileName = "test.zip";
// 设置浏览器显示的内容类型为Zip
response.setContentType("application/zip");
response.addHeader("Content-Disposition", "attachment;filename="
+ new String(fileName.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1));
ZipFile zipFile = new ZipFile(fileName);
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
for(Enumeration e = zipFile.entries(); e.hasMoreElements();) {
ZipEntry entryIn = (ZipEntry) e.nextElement();
if (entryIn.getName().contains("需要修改的路径名")) {
zos.putNextEntry(new ZipEntry(entryIn.getName().replace("需要修改的路径名", "修改后的路径名")));
}
else {
zos.putNextEntry(entryIn);
}
InputStream is = zipFile.getInputStream(entryIn);
byte [] buf = new byte[1024];
int len;
while((len = (is.read(buf))) > 0) {
zos.write(buf, 0, len);
}
zos.closeEntry();
}
zos.close();
}