继续多个SVG格式文件压缩下载

将多个SVG压缩并下载出来,记录

(controller层)代码:

 //List<File> srcfile文件集合
        byte[] buf = new byte[1024];
        // 获取输出流
        ByteArrayOutputStream bos = new ByteArrayOutputStream();

        try {
            // ZipOutputStream类:完成文件或文件夹的压缩
            ZipOutputStream out = new ZipOutputStream(bos);
            for (int i = 0; i < srcfile.size(); i++) {
                // 此处可用任意其他输入流将FileInputStream取代,outputStream为其他步骤的输出流
                FileInputStream in = new FileInputStream(srcfile.get(i));
                // 给列表中的文件单独命名
                out.putNextEntry(new ZipEntry(srcfile.get(i).getName()));
                int len;
                while ((len = in.read(buf)) > 0) {
                    out.write(buf, 0, len);
                }
                out.closeEntry();
                in.close();
                //删除临时文件
                MultipartFileToFile.delteTempFile(srcfile.get(i));
            }
            out.close();
            bos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        // 设置http响应头
        HttpHeaders header = new HttpHeaders();
        header.add("Content-Disposition", "attachment;filename=" + "在线翻译压缩包.zip");
        return new ResponseEntity<byte[]>(bos.toByteArray(), header, HttpStatus.CREATED);

http://www.sketchchina.com/read-699.html