Android解压缩zip的实现
来源:互联网 发布:Tomcat不用绑定域名 编辑:程序博客网 时间:2024/06/05 09:09
android 解压缩zip包,需要在menifest.xml中加入sdcard读写权限,如下:
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
实现代码:
/**
* 解压缩文件到指定的目录.
*
* @param unZipfileName 需要解压缩的文件
* @param mDestPath 解压缩后存放的路径
*/
public static void unZip(String unZipfileName, String mDestPath) {
if (!mDestPath.endsWith("/")) {
mDestPath = mDestPath + "/";
}
FileOutputStream fileOut = null;
ZipInputStream zipIn = null;
ZipEntry zipEntry = null;
File file = null;
int readedBytes = 0;
byte buf[] = new byte[4096];
try {
zipIn = new ZipInputStream(new BufferedInputStream(new FileInputStream(unZipfileName)));
while ((zipEntry = zipIn.getNextEntry()) != null) {
file = new File(mDestPath + zipEntry.getName());
if (zipEntry.isDirectory()) {
file.mkdirs();
} else {
// 如果指定文件的目录不存在,则创建之.
File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
fileOut = new FileOutputStream(file);
while ((readedBytes = zipIn.read(buf)) > 0) {
fileOut.write(buf, 0, readedBytes);
}
fileOut.close();
}
zipIn.closeEntry();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
实现代码:
/**
* 解压缩文件到指定的目录.
*
* @param unZipfileName 需要解压缩的文件
* @param mDestPath 解压缩后存放的路径
*/
public static void unZip(String unZipfileName, String mDestPath) {
if (!mDestPath.endsWith("/")) {
mDestPath = mDestPath + "/";
}
FileOutputStream fileOut = null;
ZipInputStream zipIn = null;
ZipEntry zipEntry = null;
File file = null;
int readedBytes = 0;
byte buf[] = new byte[4096];
try {
zipIn = new ZipInputStream(new BufferedInputStream(new FileInputStream(unZipfileName)));
while ((zipEntry = zipIn.getNextEntry()) != null) {
file = new File(mDestPath + zipEntry.getName());
if (zipEntry.isDirectory()) {
file.mkdirs();
} else {
// 如果指定文件的目录不存在,则创建之.
File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
fileOut = new FileOutputStream(file);
while ((readedBytes = zipIn.read(buf)) > 0) {
fileOut.write(buf, 0, readedBytes);
}
fileOut.close();
}
zipIn.closeEntry();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
- Android解压缩zip的实现
- Android上实现zip解压缩
- Android平台中实现Zip文件的解压缩功能
- Java实现的ZIP解压缩工具类
- C++ 实现zip解压缩
- android 解压缩zip
- Android Zip压缩解压缩
- Android Zip压缩解压缩
- Android Zip压缩解压缩
- Android Zip压缩解压缩
- Android中的Zip解压缩
- android 解压缩zip包
- Android中用Java代码实现zip文件解压缩
- Android中用Java代码实现zip文件解压缩(二)
- Android解压缩ZIP / GZIP数据(基于InflaterInputStream实现)
- Android中用Java代码实现zip文件解压缩
- Java实现zip压缩/解压缩
- Java实现zip压缩/解压缩
- linux下的sftp命令
- android完全退出应用程序的三种方式
- 配置使用Ubuntu开发环境(一)
- 设计模式之(十)桥接模式Bridge
- 补充“为什么Scrum不行”
- Android解压缩zip的实现
- Android 启动分析 --- init.c (system/core/init/init.c)
- MFC中線程掛起方法
- POJ1161 几何+floyd+枚举
- SharpZip
- 最近看了一部韩剧,叫《城市猎人》。。。。
- 二层架构与三层架构记述
- iphoneOS与Windwos下RTSP服务器与客户端的搭建
- 很朴素的学习嵌入式系统的经验