String zipFileName = “D:/developPJ/ams/workspace/ArchivesPJ/archives/src/main/webapptemp_download/test.zip”;
File zipFile = new File(zipFileName);
ZipOutputStream zipOut = new ZipOutputStream(new FileOutputStream(zipFile));
// zip的名称为
zipOut.setComment(“test.zip”);
List<File> fileList = new ArrayList<File>();

List<AmsImagesCw> imgList = financeService.selectAmsImagesCw(archiveId);
for (AmsImagesCw ImagesCw : imgList) {
fileList.add(new File(ImagesCw.getImagePath()));

for (int i = 0; i < fileList.size(); ++i) {
File file1 = fileList.get(i);
zipOut.putNextEntry(new ZipEntry(file1.getName()));
zipOut.write(FileUtils.readFileToByteArray(file1));
}
String filePath = zipFileName;
File file = new File(filePath);
String filename = “test.zip”;
FileInputStream fis = new FileInputStream(file);
OutputStream os = response.getOutputStream();
response.setHeader(“Content-Disposition”, “attachment;filename=”
+ new String(filename.getBytes(“gb2312”), “iso8859-1”));
response.setCharacterEncoding(“utf-8”);
os.write(FileUtils.readFileToByteArray(zipFile));
os.flush();
fis.close();

zipOut.close();
// 输出客户端结束后,删除压缩包
if (zipFile.exists()) {
zipFile.delete();
}

版权声明:本文为swp520lmg原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/swp520lmg/articles/6429111.html