/**
* 解压含有文件夹的压缩包
* @param zipFile 解压的路径
* @param targetDir 目标路径
*/
public void unZip(String zipFile, String targetDir) {
int BUFFER = 4096; //缓冲区
String strEntry; //保存每个zip的条目名称
try {
BufferedOutputStream dest = null;
FileInputStream fis = new FileInputStream(zipFile);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry; //每个zip条目的实例
while ((entry = zis.getNextEntry()) != null) {
try {
int count;
byte data[] = new byte[BUFFER];
strEntry = entry.getName();
File entryFile = new File(targetDir + "/" + strEntry);
File entryDir = new File(entryFile.getParent());
if (!entryDir.exists()) {
entryDir.mkdirs();
} else {
if (!entryFile.isDirectory()) {
if (!entryFile.exists()) {
entryFile.mkdirs();
}
} else {
if (!entryFile.exists()) {
entryFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(entryFile);
dest = new BufferedOutputStream(fos, BUFFER);
while ((count = zis.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
zis.close();
} catch (Exception cwj) {
cwj.printStackTrace();
}
}
* 解压含有文件夹的压缩包
* @param zipFile 解压的路径
* @param targetDir 目标路径
*/
public void unZip(String zipFile, String targetDir) {
int BUFFER = 4096; //缓冲区
String strEntry; //保存每个zip的条目名称
try {
BufferedOutputStream dest = null;
FileInputStream fis = new FileInputStream(zipFile);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry; //每个zip条目的实例
while ((entry = zis.getNextEntry()) != null) {
try {
int count;
byte data[] = new byte[BUFFER];
strEntry = entry.getName();
File entryFile = new File(targetDir + "/" + strEntry);
File entryDir = new File(entryFile.getParent());
if (!entryDir.exists()) {
entryDir.mkdirs();
} else {
if (!entryFile.isDirectory()) {
if (!entryFile.exists()) {
entryFile.mkdirs();
}
} else {
if (!entryFile.exists()) {
entryFile.createNewFile();
}
FileOutputStream fos = new FileOutputStream(entryFile);
dest = new BufferedOutputStream(fos, BUFFER);
while ((count = zis.read(data, 0, BUFFER)) != -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
}
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
zis.close();
} catch (Exception cwj) {
cwj.printStackTrace();
}
}