public void downloadZipFile( HttpServletResponse response) throws IOException {
byte[] bytes1=null;
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
ZipOutputStream zip = new ZipOutputStream(outputStream);
//TODO 下面做循环压缩
for(int i=1;i<=2;i++){
bytes1 = new byte[8192];
//添加到zip,一定要加目录
zip.putNextEntry(new ZipEntry("test" + File.separator + "test"+i+".txt""));
IOUtils.write(bytes1, zip);
zip.closeEntry();
}
IOUtils.closeQuietly(zip);
byte[] data = outputStream.toByteArray();
response.reset();
response.setContentType("application/octet-stream; charset=UTF-8");
response.setHeader("Content-Disposition", "attachment;filename="+ new String(("test" + ".zip").getBytes(), "UTF-8"));
IOUtils.write(data, response.getOutputStream());
}