您的位置:首页 > 移动开发 > Android开发

Android 解压缩ZIP文件操作

2015-05-18 20:22 218 查看
Android 解压缩ZIP文件操作,直接看代码:

/**
* 解压缩zip文件,耗时操作,建议放入异步线程
*
* */
public static void unzip(String targetPath, String zipFilePath) {
try {
int BUFFER = 2048;
String fileName = zipFilePath;
String filePath = targetPath;
ZipFile zipFile = new ZipFile(fileName);
Enumeration emu = zipFile.entries();
int i = 0;
while (emu.hasMoreElements()) {
ZipEntry entry = (ZipEntry) emu.nextElement();
if (entry.isDirectory()) {
new File(filePath + entry.getName()).mkdirs();
continue;
}
BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(entry));
File file = new File(filePath + entry.getName());
File parent = file.getParentFile();
if (parent != null && (!parent.exists())) {
parent.mkdirs();
}
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos, BUFFER);

int count;
byte data[] = new byte[BUFFER];
while ((count = bis.read(data, 0, BUFFER)) != -1) {
bos.write(data, 0, count);
}
bos.flush();
bos.close();
bis.close();
}
zipFile.close();
} catch (Exception e) {
e.printStackTrace();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: