一下代码实现的是将多个文件进行压缩,采用的是边压缩边下载的方式
/**
* 压缩文件
* @param exportFilePathList
* @param response
*/
public static void downloadPictureZip(List exportFilePathList, HttpServletResponse response) {
ZipOutputStream zipos = null;
try {
zipos = new ZipOutputStream(new BufferedOutputStream(response.getOutputStream()));
zipos.setMethod(ZipOutputStream.DEFLATED);// 设置压缩方法DEFLATED
} catch (Exception e) {
e.printStackTrace();
}
DataOutputStream os = null;
// 循环将文件写入压缩流
for (String filePath : exportFilePathList) {
File file = new File(filePath);
try {
// 添加ZipEntry,并ZipEntry中写入文件流
zipos.putNextEntry(new ZipEntry(file.getName()));
os = new DataOutputStream(zipos);
InputStream is = new FileInpu