public static boolean unZip(String zipDirectory, String storageDirectory,
String fileName) {
boolean result = false;
String zipName = zipDirectory + fileName;
String filePath = storageDirectory;
ZipFile zipFile = null;
BufferedInputStream bis = null;
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try {
zipFile = new ZipFile(zipName);
Enumeration<? extends ZipEntry> emu = zipFile.entries();
while (emu.hasMoreElements()) {
ZipEntry entry = (ZipEntry) emu.nextElement();
if (entry.isDirectory()) {
new File(filePath + entry.getName()).mkdirs();
continue;
}
bis = new BufferedInputStream(zipFile.getInputStream(entry));
File file = new File(filePath + entry.getName());
File parent = file.getParentFile();
if (parent != null && (!parent.exists())) {
parent.mkdirs();
}
fos = new FileOutputStream(file);
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();
}
result = true;
}
catch (Exception e) {
e.printStackTrace();
result = false;
}
finally {
try {
if (null != bos) {
bos.close();
}
if (null != bis) {
bis.close();
}
if (null != zipFile) {
zipFile.close();
}
}
catch (IOException e) {
e.printStackTrace();
result = false;
}
}
return result;
}
原来写过的一个解压方法,可以正常解压。zipDirectory 是压缩文件路径
storageDirectory 是解压文件路径
fileName 是压缩文件名(xxx.zip)
解决方案 »
- 如何用显示listview点击后的单选背景效果
- android开发统计单个应用的wifi流量
- 有谁能描述一下从一个程序调用外部程序后再返回来的程序生命周期
- Android 模拟器上的源代码哪里找
- 请问android sdk版本和android版本有什么关系?
- 为什么在子线程中可以更新UI?如下面的代码!
- 如何进行数据类型转换?byte[] -> int
- the application has stopped unexpectedly
- android文件操作案例初学中遇到的问题
- android webview问题
- javapos ptr.open打印机 出错
- 【开发分享】如何提高移动应用的活跃度
带.在linux系统默认是隐藏文件夹。
在file explorer中是看不到的。
在shell命令下可以用 ls -a看到。
我这个方法是利用zipEntry进行的按文件夹进行压缩。可能跟你的压缩方式不一样。如果需要的话我可以把doZip发给你。
下次回复记得点引用。要不我这里没有提示
呵呵, 最近也在搞这个东西
LZ 可以借鉴一下如下博文
http://blog.csdn.net/spjhandsomeman/article/details/8140182希望有所帮助