123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package com.huimv.manage.util;
- import java.io.*;
- import java.util.List;
- import java.util.zip.ZipEntry;
- import java.util.zip.ZipOutputStream;
- /**
- * @Project : huimv.shiwan
- * @Package : com.huimv.biosafety.uface.controller
- * @Description : TODO
- * @Version : 1.0
- * @Author : ZhuoNing
- * @Create : 2020-12-25
- **/
- public class ZipUtils {
- public static void downloadZip(OutputStream outputStream, File file){
- BufferedInputStream bufferedInputStream = null;
- ZipOutputStream zipOutputStream = null;
- try {
- zipOutputStream = new ZipOutputStream(outputStream);
- // for (File file : fileList) {
- ZipEntry zipEntry = new ZipEntry(file.getName());
- zipOutputStream.putNextEntry(zipEntry);
- byte[] buf = new byte[1024];
- int len;
- FileInputStream in = new FileInputStream(file);
- while ((len = in.read(buf)) != -1) {
- zipOutputStream.write(buf, 0, len);
- zipOutputStream.flush();
- }
- // }
- zipOutputStream.flush();
- zipOutputStream.close();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- // 关闭流
- try {
- if (bufferedInputStream != null) {
- bufferedInputStream.close();
- }
- if (zipOutputStream != null ) {
- zipOutputStream.close();
- }
- if (outputStream != null) {
- outputStream.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- }
|