public static void zipFiles(File[] srcfile,ServletOutputStream sos){
    byte[] buf=new byte[1024];
    try {
        //ZipOutputStream类:完成文件或文件夹的压缩
        ZipOutputStream out=new ZipOutputStream(sos);
        for(int i=0;i<srcfile.length;i++){
            FileInputStream in=new FileInputStream(srcfile[i]);
            out.putNextEntry(new ZipEntry(srcfile[i].getName()));
            int len;
            while((len=in.read(buf))>0){
                out.write(buf,0,len);
            }
            out.closeEntry();
            in.close();
        }
        out.close();
        System.out.println("压缩完成.");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
相关资源
相似解决方案