zoukankan      html  css  js  c++  java
  • 文件压缩和解压缩工具类

    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;  

           }

    }

  • 相关阅读:
    vim 多窗口编辑
    opengl笔记——旋转,一段代码的理解
    用条件变量实现事件等待器的正确与错误做法
    opengl笔记—— glMultMatrixf() 区别 glLoadMatrixf()
    Mule与其它web应用服务器的区别
    海量数据相似度计算之simhash短文本查找
    关于协方差矩阵的理解
    C++ STL中的常用容器浅谈
    唐-诗:《枫桥夜泊》
    唐-诗:《肚桑干》
  • 原文地址:https://www.cnblogs.com/lxaic/p/4990711.html
Copyright © 2011-2022 走看看