/**
* 导出zip文件 list<String> 为 写入到本地的文件
* @param request
* @param response
* @param exportExcel
* @param fileName
*/
public static void writeOutZip(HttpServletRequest request, HttpServletResponse response, List<String> names) {
File srcfile[] = new File[names.size()];
ZipOutputStream out = null;
FileInputStream in = null;
try {
// out = new ZipOutputStream(response.getOutputStream());
out = new ZipOutputStream(new FileOutputStream("daochu.zip"));
for (int i = 0, n1 = names.size(); i < n1; i++) {
//System.out.println(i);
srcfile[i] = new File(names.get(i));
}
byte[] buf = new byte[4096];
for (int i = 0; i < srcfile.length; i++) {
//System.out.println("4 " + i + " " + srcfile[i]);
in = new FileInputStream(srcfile[i]);
//System.out.println("5 " + i);
out.putNextEntry(new ZipEntry(names.get(i)));
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
out.closeEntry();
in.close();
}
out.close();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
in.close();
out.close();
deleteFile(names);
} catch (IOException e) {
e.printStackTrace();
}
}
}
导出 zip 压缩文件
最新推荐文章于 2025-05-26 14:53:58 发布