在AndroidManifest.xml里添加权限:

<uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE"/> 
 <uses-permissionandroid:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>

工具类:

public class ZIP {public ZIP(){}/** * DeCompress the ZIP to the path * @param zipFileString  name of ZIP * @param outPathString   path to be unZIP* @throws Exception */  public static void UnZipFolder(String zipFileString, String outPathString) throws Exception {  ZipInputStream inZip = new ZipInputStream(new FileInputStream(zipFileString));  ZipEntry zipEntry;  String szName = "";  while ((zipEntry = inZip.getNextEntry()) != null) {  szName = zipEntry.getName();  if (zipEntry.isDirectory()) {  // get the folder name of the widget  szName = szName.substring(0, szName.length() - 1);  File folder = new File(outPathString + File.separator + szName);  folder.mkdirs();  } else {  File file = new File(outPathString + File.separator + szName);  file.createNewFile();  // get the output stream of the file  FileOutputStream out = new FileOutputStream(file);  int len;  byte[] buffer = new byte[1024];  // read (len) bytes into buffer  while ((len = inZip.read(buffer)) != -1) {  // write (len) byte from buffer at the position 0  out.write(buffer, 0, len);  out.flush();  }  out.close();  }  } inZip.close();  }/** * Compress file and folder* @param srcFileString   file or folder to be Compress* @param zipFileString   the path name of result ZIP* @throws Exception */  public static void ZipFolder(String srcFileString, String zipFileString)throws Exception {  //create ZIP ZipOutputStream outZip = new ZipOutputStream(new FileOutputStream(zipFileString));  //create the file File file = new File(srcFileString);  //compressZipFiles(file.getParent()+File.separator, file.getName(), outZip);  //finish and closeoutZip.finish();  outZip.close();  }/** * compress files* @param folderString * @param fileString * @param zipOutputSteam * @throws Exception */  private static void ZipFiles(String folderString, String fileString, ZipOutputStream zipOutputSteam)throws Exception{  if(zipOutputSteam == null)  return;  File file = new File(folderString+fileString);  if (file.isFile()) {  ZipEntry zipEntry =  new ZipEntry(fileString);  FileInputStream inputStream = new FileInputStream(file);  zipOutputSteam.putNextEntry(zipEntry);  int len;  byte[] buffer = new byte[4096];   while((len=inputStream.read(buffer)) != -1)  {  zipOutputSteam.write(buffer, 0, len);  }  zipOutputSteam.closeEntry();  }  else {  //folderString fileList[] = file.list();  //no child file and compress  if (fileList.length <= 0) {  ZipEntry zipEntry =  new ZipEntry(fileString+File.separator);  zipOutputSteam.putNextEntry(zipEntry);  zipOutputSteam.closeEntry();                  }  //child files and recursion  for (int i = 0; i < fileList.length; i++) {  ZipFiles(folderString, fileString+java.io.File.separator+fileList[i], zipOutputSteam);  }//end of for  }    }/** * return the InputStream of file in the ZIP* @param zipFileString  name of ZIP * @param fileString     name of file in the ZIP * @return InputStream * @throws Exception */  public static InputStream UpZip(String zipFileString, String fileString)throws Exception {  ZipFile zipFile = new ZipFile(zipFileString);  ZipEntry zipEntry = zipFile.getEntry(fileString);  return zipFile.getInputStream(zipEntry);  }  /** * return files list(file and folder) in the ZIP* @param zipFileString     ZIP name* @param bContainFolder    contain folder or not* @param bContainFile      contain file or not* @return * @throws Exception */  public static List<File> GetFileList(String zipFileString, boolean bContainFolder, boolean bContainFile)throws Exception {  List<File> fileList = new ArrayList<File>();  ZipInputStream inZip = new ZipInputStream(new FileInputStream(zipFileString));  ZipEntry zipEntry;  String szName = "";  while ((zipEntry = inZip.getNextEntry()) != null) {  szName = zipEntry.getName();  if (zipEntry.isDirectory()) {  // get the folder name of the widget  szName = szName.substring(0, szName.length() - 1);  File folder = new File(szName);  if (bContainFolder) {  fileList.add(folder);  }  } else {  File file = new File(szName);  if (bContainFile) {  fileList.add(file);  }  }  }inZip.close();  return fileList;  }
}

android解压ZIP文件相关推荐

  1. Android 解压zip文件

    过了n多天后,当再次使用原先博客上写的那篇: Android 压缩解压zip文件 去做zip包的解压的时候,出现了原来没有发现的很多问题.首先是中文汉字问题,使用java的zip包不能很好的解决解压问 ...

  2. Android 解压zip文件你知道多少?

    对于Android常用的压缩格式ZIP,你了解多少? Android的有两种解压ZIP的方法,你知道吗? ZipFile和ZipInputStream的解压效率,你对比过吗? 带着以上问题,现在就开始 ...

  3. android解压zip文件进度条,Android实现文件解压带进度条功能

    解压的工具类 package com.example.videodemo.zip; public class ZipProgressUtil { /*** * 解压通用方法 * * @param zi ...

  4. Android 解压Zip文件,中文乱码

    参考自:中文乱码 直接上代码: package com.xxx.utils;import android.util.Log;import java.io.BufferedInputStream; im ...

  5. java csv文件tozip后损坏_java上传并下载以及解压zip文件有时会报文件被损坏错误分析以及解决...

    情景描述: 1.将本地数据备份成zip文件: 2.将备份的zip文件通过sftp上传到文件服务器: 3.将文件服务器上的zip文件下载到运行服务器: 4.将下载的zip文件解压到本地(文件大小超过50 ...

  6. java 解压文件_java实现解压zip文件,(亲测可用)!!!!!!

    项目结构: Util.java内容: package com.cfets.demo; import java.io.File; import java.io.FileOutputStream; imp ...

  7. 【Android 安全】DEX 加密 ( 代理 Application 开发 | 解压 apk 文件 | 判定是否是第一次启动 | 递归删除文件操作 | 解压 Zip 文件操作 )

    文章目录 一.判定是否是第一次启动 二.递归删除文件操作 三.解压 Zip 文件操作 四.解压操作相关代码 参考博客 : [Android 安全]DEX 加密 ( 常用 Android 反编译工具 | ...

  8. android zip格式应用,Android 压缩解压zip文件

    Android 压缩解压zip文件 上次写了个解压缩功能,但有局限性,比如压缩文件xx.zip 里包括子目录的情况下,执行上次解压缩的功能就不能实现我们想要的效果,于是在网上参考了一下java的解压缩 ...

  9. android zip解压进度_android zip4j之--解压zip文件并实时显示解压进度

    Zip文件是我们经常用到压缩文件格式,android中在进行网络请求大批量数据时,通常会采用传递zip文件,这样做即可以减少网络流量的消耗,加快请求的响应速度,又可以减少对存储空间的要求,所以当我们将 ...

最新文章

  1. Eclipse在Ubuntu8.04桌面系统下安装和弹出空白对话框
  2. wxWidgets:wxCheckListBox类用法
  3. 绘画 某种字体 以某种折行规则 最后画出的text有多大
  4. 汇编学习笔记(二)--数据处理的两个基本问题
  5. 被LTRIM(RTRIM())害死了,差点
  6. 方舟非主机服务器无限距离,方舟非专业服务器距离限制怎么解除 | 手游网游页游攻略大全...
  7. 构建高性能WEB站点笔记二
  8. HTML5的革新:结构之美
  9. 记录一次众测平台邀请码获取
  10. 华为云服务查找手机_华为云服务里面的手机找回需要什么条件
  11. 电脑版微信公众号文章加载不出来,空白的可能解决办法
  12. 阿里云STMP实现邮件发送
  13. (六)分布式系统认证方案
  14. 终于还是对闲鱼下手了。闲鱼爬虫,idlefish spider来了
  15. 汽车数据聚类分析——天池竞赛
  16. 【2. Redis 高级数据结构】
  17. win10打开蓝牙_这4个Win10新增的快捷键,提高效率必备
  18. ASIL-汽车安全完整性等级
  19. WOFOST模型Matlab,一种WOFOST-PAR耦合模型建立方法与流程
  20. 【视觉AI训练营day2】身份证识别web应用

热门文章

  1. python svr回归_python机器学习库scikit-learn:SVR的基本应用
  2. 牛顿迭代法求平方根、立方根(计算一个数字的平方根、立方根,不使用库函数)
  3. 《锋味》谢霆锋柬埔寨吃蜘蛛 邓紫棋为大象唱“泡沫”
  4. Maven+SSM框架项目实例
  5. CET-6六级考前冲刺 听力 Tuesday
  6. 步进电机的匀加速程序
  7. 【Java中IO流】面试知识点总结
  8. mybatis的parameterType属性那些情况下要写 哪些情况下不用写
  9. u盘盘符不显示 win10_Win10不显示U盘的盘符怎么办
  10. VirtualBox 虚拟机无法启动