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;  

           }

    }

  • 相关阅读:
    python笔记——调试和异常处理
    [算法学习] 线段树,树状数组,数堆,笛卡尔树
    【cpp】G++中不支持static_cast?
    【生活感想】不够淡定
    数值线性代数小结
    伪逆
    统计机器学习
    Numerical Methods with MATLAB(1)
    吐槽iOS国际化:关于NSLocalizedString的使用
    iOS 沙盒路径操作:新建/删除文件和文件夹
  • 原文地址:https://www.cnblogs.com/lxaic/p/4990711.html
Copyright © 2011-2022 走看看