文件压缩和解压缩工具类

public class ZipHelper {  

          public static void compress(InputStream is, OutputStream os, String entry) throws Exception{

                        byte[] bytes = new byte[1024 * 8];

                        ZipOutputStream zos = new ZipOutputStream(os);

                        if(entry != null)    zos.putNextEntry(new ZipEntry(entry));

                        int count = 0;  

                        while((count = is.read(bytes)) > 0){    

                                  zos.write(bytes,0,count);  

                        }      

                        zos.flush();   

                        zos.close();  

           }

          public static ByteArrayOutputStream decompression(ZipInputStream zis) throws Exception{

                       ByteArrayOutputStream bos = new ByteArrayOutputStream();

                       byte[] bytes = new byte[1024 * 8];   

                       while(zis.getNextEntry() != null){   

                               int count = 0;    

                               while((count = zis.read(bytes)) > 0){     

                                         bos.write(bytes,0,count);  

                               } 

                       }

                       return bos;  

       }

}

posted @ 2015-11-24 10:27  神玄晓  阅读(130)  评论(0编辑  收藏  举报