//定义assetmanager对象
AssetManager assetManager = getAssets();
// 需要解压的对象
InputStream dataSource = assetManager.open("ShiningTrip.zip");
// 調用解压的方法
ZipUtil.unzip(dataSource, android.os.Environment
.getExternalStorageDirectory() + "");




public static void unzip(InputStream zipFileName, String outputDirectory) {
try {
ZipInputStream in = new ZipInputStream(zipFileName);
// 获取ZipInputStream中的ZipEntry条目,一个zip文件中可能包含多个ZipEntry,
// 当getNextEntry方法的返回值为null,则代表ZipInputStream中没有下一个ZipEntry,
// 输入流读取完成;
ZipEntry entry = in.getNextEntry();
while (entry != null) {

// 创建以zip包文件名为目录名的根目录
File file = new File(outputDirectory);
file.mkdir();
if (entry.isDirectory()) {
String name = entry.getName();
name = name.substring(0, name.length() - 1);

file = new File(outputDirectory + File.separator + name);
file.mkdir();

} else {
file = new File(outputDirectory + File.separator + entry.getName());
file.createNewFile();
FileOutputStream out = new FileOutputStream(file);
int b;
while ((b = in.read()) != -1) {
out.write(b);
}
out.close();
}
// 读取下一个ZipEntry
entry = in.getNextEntry();
}
in.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}

更多相关文章

  1. 新浪微博Oauth2.0授权认证及SDK、API的使用(Android)
  2. android源码编译出现No private recovery resources for TARGET_
  3. Android_查看linux内核版本和android文件系统版本
  4. android IApplicationToken分析
  5. android学习资料与资源记录
  6. Android应用程序组件Content Provider在应用程序之间共享数据的
  7. Android(安卓)面试题(经典)
  8. appt命令检测Apk信息的方法
  9. android通用适配器

随机推荐

  1. 深入理解Android日志系统
  2. Android Activity和Intent机制
  3. (2019年10月更新) Android 最全的底部导
  4. Android炫酷的3D球型标签云开源库 3dTagC
  5. Android(安卓)Switch控件介绍
  6. 安卓 打开app进入第一个指定的Activity
  7. Android_百度地图BaiduMap_LocationClien
  8. 韩老师安卓笔记
  9. Android 锁屏生命周期问题
  10. 今天开始写android的照片浏览器(一)至返回