以流的形式返回多图片zip压缩包
public void download(HttpServletResponse response){
try {
String downloadFilename = System.currentTimeMillis()+"_资料.zip";
downloadFilename = URLEncoder.encode(downloadFilename, "UTF-8");
response.setContentType("application/octet-stream");
response.setHeader("Content-Disposition", "attachment;filename=" + downloadFilename);
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
for (int i = 0; i < files.length; i++) {
zos.putNextEntry(new ZipEntry(i + ".jpg"));
URL url = new URL(“www.xxxx.com/xxx/xxx.jpg”]);
InputStream fis = url.openConnection().getInputStream();
FIle file = new FIle("D://XXX/XXX/XXX.jpg");
InputStream fis = new FileInputStream(file);
byte[] buffer = new byte[1024];
int r = 0;
while ((r = fis.read(buffer)) != -1) {
zos.write(buffer, 0, r);
}
fis.close();
}
zos.flush();
zos.close();
} catch (UnsupportedEncodingException e) {
log.info("下载用户资料图片出异常了",e.getMessage());
} catch (IOException e) {
log.info("下载用户资料图片出异常了",e.getMessage());
}
}