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)
带.在linux系统默认是隐藏文件夹。
在file explorer中是看不到的。
在shell命令下可以用 ls -a看到。
我这个方法是利用zipEntry进行的按文件夹进行压缩。可能跟你的压缩方式不一样。如果需要的话我可以把doZip发给你。
下次回复记得点引用。要不我这里没有提示
呵呵, 最近也在搞这个东西
LZ 可以借鉴一下如下博文
http://blog.csdn.net/spjhandsomeman/article/details/8140182希望有所帮助