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

01 privatestaticvoidUnzip(String zipFile, String targetDir) {
02   intBUFFER =4096//这里缓冲区我们使用4KB,
03   String strEntry;//保存每个zip的条目名称
04   try{
05   BufferedOutputStream dest =null//缓冲输出流
06   FileInputStream fis =newFileInputStream(zipFile);
07   ZipInputStream zis =newZipInputStream(newBufferedInputStream(fis));
08   ZipEntry entry;//每个zip条目的实例
09   while((entry = zis.getNextEntry()) !=null) {
10   try{
11   Log.i("Unzip: ""="+ entry);
12   intcount;
13   bytedata[] =newbyte[BUFFER];
14   strEntry = entry.getName();
15   File entryFile =newFile(targetDir + strEntry);
16   File entryDir =newFile(entryFile.getParent());
17   if(!entryDir.exists()) {
18   entryDir.mkdirs();
19   }
20   FileOutputStream fos =newFileOutputStream(entryFile);
21   dest =newBufferedOutputStream(fos, BUFFER);
22   while((count = zis.read(data,0, BUFFER)) != -1) {
23   dest.write(data,0, count);
24   }
25   dest.flush();
26   dest.close();
27   }catch(Exception ex) {
28   ex.printStackTrace();
29   }
30   }
31   zis.close();
32   }catch(Exception cwj) {
33   cwj.printStackTrace();
34   }
35   }


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

更多相关文章

  1. Android中运用Pull解析器读取XML文件
  2. android音频视频播放器
  3. Android(安卓)framebuffer 截屏原理
  4. Android(安卓)存储:Internal Storage的用法以及与External storag
  5. Android(安卓)中自定义 Menu 资源
  6. Android(安卓)JNI入门第二篇――Java参数类型与本地参数类型对照
  7. Android安全机制之反编译
  8. Android(安卓)通过zygote来运行java程序
  9. Android(安卓)SDK tools adb.exe下文件丢失问题

随机推荐

  1. Android(安卓)Vibrator 的用法
  2. Android:UI控件AutoCompleteTextView、Mul
  3. Android(安卓)使用Javascript作为脚本计
  4. 使用Uiautomator遇到的问题
  5. Android设备兼容性 1
  6. Android(安卓)Studio安装及首次运行遇到
  7. 百度云推送实践
  8. android中使用zxing扫描二维码以及条形码
  9. Android的安装过程
  10. Android(安卓)AsyncTask 原理及Java多线