生成压缩文件

files:是所有文件的目录
destZip:是生成压缩文件所存放的目录


public static void zipFiles(Collection<String> files,String destZip){   FileOutputStream fout=null;   ZipOutputStream zout=null;    int len=-1;    byte[] buf=new byte[1024];   try{     FileInputStream fin=null;     fout=new FileOutputStream(destZip);     zout=new ZipOutputStream(fout);     zout.setEncoding("gbk");     for(String reportPath:files){       File repostFile= new File(reportPath);       String reportName= reportFile.getName();       ZipEntry zEntry = new ZipEntry(reportName);       zout.putNextEntry(zEntry);       fin=new FileInputStream(reportFile);     while(len=fin.read(buf))!=-1){     zout.write(buf,0,len);   }   fin.close(); } }catch(Exception e){ e.printStackTrace(); }finally{ try{ fout.close(); }catch(IOExecption e){ e.printStackTrace(); }finally{ } } } }
原文地址:https://www.cnblogs.com/zhangxuesong/p/5671388.html