@RequestMapping(value = {"/downloadImg.html"}, method = {RequestMethod.GET, RequestMethod.POST})
public void downloadImg(HttpServletRequest request, HttpServletResponse response) throws Exception{
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000);
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename="+ newFileName + ".zip");
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
File[] files = new File[2];
files[0] = new File("D:\\pd1.jpg");
files[1] = new File("D:\\pd2.jpg");
for (int i = 0; i < files.length; i++) {
File f = files[i];
zos.putNextEntry(new ZipEntry(f.getName()));
FileInputStream fis = new FileInputStream(f);
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();
}
public void downloadImg(HttpServletRequest request, HttpServletResponse response) throws Exception{
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
String newFileName = df.format(new Date()) + "_" + new Random().nextInt(1000);
response.setContentType("APPLICATION/OCTET-STREAM");
response.setHeader("Content-Disposition", "attachment; filename="+ newFileName + ".zip");
ZipOutputStream zos = new ZipOutputStream(response.getOutputStream());
File[] files = new File[2];
files[0] = new File("D:\\pd1.jpg");
files[1] = new File("D:\\pd2.jpg");
for (int i = 0; i < files.length; i++) {
File f = files[i];
zos.putNextEntry(new ZipEntry(f.getName()));
FileInputStream fis = new FileInputStream(f);
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();
}