多文件压缩

public class ZipOutputStreamDemo {
    public static File zipFiles(List<File> srcFiles) {
       
        String zipFileName = “压缩文件名”;   // d:/file/file.rar;
        File zipFile = new File(zipFileName);
        int bufSize = 2048;
        byte[] buf = new byte[bufSize];
        try{

         ZipOutputStream out = new ZipoutputStream(new     
                   FileOutputStream(zipFile));
             for(int i=0;i<srcFiles.size();i++){
             FileInputStream in = new FileInputStream(srcFiles.get(i));
             String str = srcFiles.get(i).getName;
             out.putNextEntry( new ZipEntry(str));
             int len = 0;
             while ((len = in.read(buf,0,bufSize)) > 0){
             out.write(buf,0,len);
       }
       out.closeEntry();
       in.close();
       }
       out.flush();
       out.close();
 }     
 catch (Exception e) {
 logger.error("",e);
}
return zipFiles;
}            
             

 

posted @ 2017-11-02 10:43  一只菜机  阅读(165)  评论(0编辑  收藏  举报