zoukankan      html  css  js  c++  java
  • Android Zip文件解压缩代码

     

    2011-04-01 17:58:52|  分类: Android |举报 |字号 订阅

     
    在Android平台中如何实现Zip文件的解压 缩功能呢? 因为Android内部已经集成了zlib库,对于英文和非密码的Zip文件解压缩还是比较简单的,下面Android123给大家一个解压缩zip的 java代码,可以在Android上任何版本中使用,Unzip这个静态方法比较简单,参数一为源zip文件的完整路径,参数二为解压缩后存放的文件 夹。

    private static void Unzip(String zipFile, String targetDir) {
       int BUFFER = 4096; //这里缓冲区我们使用4KB,
       String strEntry; //保存每个zip的条目名称

       try {
        BufferedOutputStream dest = null; //缓冲输出流
        FileInputStream fis = new FileInputStream(zipFile);
        ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
        ZipEntry entry; //每个zip条目的实例

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

         try {
           Log.i("Unzip: ","="+ entry);
          int count;
          byte data[] = new byte[BUFFER];
          strEntry = entry.getName();

          File entryFile = new File(targetDir + strEntry);
          File entryDir = new File(entryFile.getParent());
          if (!entryDir.exists()) {
           entryDir.mkdirs();
          }

          FileOutputStream fos = new FileOutputStream(entryFile);
          dest = new BufferedOutputStream(fos, BUFFER);
          while ((count = zis.read(data, 0, BUFFER)) != -1) {
           dest.write(data, 0, count);
          }
          dest.flush();
          dest.close();
         } catch (Exception ex) {
          ex.printStackTrace();
         }
        }
        zis.close();
       } catch (Exception cwj) {
        cwj.printStackTrace();
       }
      }

      上面是Android开发网总结的zip文件解压缩代码,希望你大家有用,需要注意的是参数均填写完整的路径,比如/mnt/sdcard/xxx.zip这样的类型。

  • 相关阅读:
    XUL
    weblogic更新license步骤
    用Eclipse+ axis2_1.1.1+tomcat5.5 开发Web Services
    网管和黑客都必须知道的命令
    WebLogic Server实现双向SSL
    配置 WebLogic 9
    JSTL fmt:formatNumber 数字、货币格式化
    关闭myeclipse的Quick Update自动更新功能
    ibatis2.3+mysql5.1+resin3.15乱码感想
    配置MyEclipse 6 自带的tomcat6
  • 原文地址:https://www.cnblogs.com/xgjblog/p/3808054.html
Copyright © 2011-2022 走看看