• java 压缩文件 传入文件数组,压缩文件,在指定路径下生成指定文件名的压缩文件


    /**
    * 传入文件数组,压缩文件,在指定路径下生成指定文件名的压缩文件
    *
    * @param files
    * 文件数组
    * @param strZipName
    * 压缩文件路径及文件名
    * @throws IOException
    */
    public static void zipFiles(List files, String strZipName) {
    if (files == null || files.size() == 0) {
    return;
    }
    byte[] buffer = new byte[2048];
    FileInputStream fis=null;
    ZipOutputStream zipOps=null;
    try{
    zipOps = new ZipOutputStream(new FileOutputStream(strZipName));
    for (File src : files) {
    fis = new FileInputStream(src);
    zipOps.putNextEntry(new ZipEntry(src.getName()));
    int len;
    // 读入需要下载的文件的内容,打包到zip文件
    while ((len = fis.read(buffer)) > 0) {
    zipOps.write(buffer, 0, len);
    }
    zipOps.closeEntry();
    fis.close();
    }
    zipOps.close();
    }catch (IOException e){
    e.printStackTrace();
    }
    }

  • 相关阅读:
    接口自动化架构-获取用例
    Windows性能监控工具Perfmon使用指南
    接口自动化架构1-setting
    多进程
    线程锁、守护线程
    多线程
    xlrd模块
    封装写日志的类
    封装redis
    继承
  • 原文地址:https://www.cnblogs.com/antis/p/5942959.html
Copyright © 2020-2023  润新知