当前位置: 首页 > news >正文

Android解压zip文件到指定目录

 很多时候需要把一个预制的zip文件解压到根目录,下面是一个实例代码:

	private static final int BUFFER_SIZE = 4096;public static void unZip(String zipFilePath, String targetDir) throws IOException {File destDir = new File(targetDir);if (!destDir.exists()) {destDir.mkdirs();}try (FileInputStream fis = new FileInputStream(zipFilePath);ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis))) {ZipEntry entry;while ((entry = zis.getNextEntry()) != null) {String entryName = entry.getName();File file = new File(destDir, entryName);if (entry.isDirectory()) {file.mkdirs();} else {extractFile(zis, file);}zis.closeEntry();}}}private static void extractFile(ZipInputStream zis, File file) throws IOException {File parent = file.getParentFile();if (!parent.exists()) {parent.mkdirs();}try (FileOutputStream fos = new FileOutputStream(file);BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER_SIZE)) {byte[] buffer = new byte[BUFFER_SIZE];int read;while ((read = zis.read(buffer)) != -1) {bos.write(buffer, 0, read);}}}

使用实例:

unZip("/system/media/xxx.zip", "/storage/emulated/0/");

包自己导入一下就行了

http://www.lryc.cn/news/489208.html

相关文章:

  • 主要用于图像的颜色提取、替换以及区域修改
  • gbase8c之运维操作
  • 云原生学习
  • 深入解析 Vue 3 中的 defineExpose
  • Docker3:docker基础1
  • 【UGUI】背包的交互01(道具信息跟随鼠标+道具信息面板显示)
  • ubuntu20.04中编译安装gcc 9.2.0
  • ss 命令的基本用法
  • Leetcode198. 打家劫舍(HOT100)
  • kafka基础
  • STM32CUBEIDE FreeRTOS操作教程(九):eventgroup事件标志组
  • Python设计模式详解之2 —— 工厂模式
  • 【Zookeeper】二、主从应用(master-worker架构)
  • Diffusion【2】:VAE
  • 高级java每日一道面试题-2024年11月19日-基本篇-获取一个类Class对象的方式有哪些?
  • xilinx xapp1171学习笔记
  • 一次需升级系统的wxpython安装(macOS M1)
  • el-table 数据去重后合并表尾合计行,金额千分位分割并保留两位小数,表尾合计行表格合并
  • Springboot整合mybatis-plus使用pageHelper进行分页
  • 【Xbim+C#】创建拉伸的墙
  • 【阅读记录-章节3】Build a Large Language Model (From Scratch)
  • three.js 对 模型使用 视频进行贴图修改材质
  • MySQL - 数据库基础 | 数据库操作 | 表操作
  • maven父子项目
  • NLP论文速读(多伦多大学)|利用人类偏好校准来调整机器翻译的元指标
  • MyBatis——#{} 和 ${} 的区别和动态 SQL
  • 解决sql字符串
  • 深度解析:Android APP集成与拉起微信小程序开发全攻略
  • Leetcode 被围绕的区域
  • ssm框架-spring-spring声明式事务