File f = new
File("c:/test.zip");
ZipFile zf = new ZipFile(f,
"gbk");
File folder = new
File("c:/test");
if (!folder.exists()) {
folder.mkdirs();
}
for
(Enumeration<ZipArchiveEntry> files = zf.getEntries();
files.hasMoreElements();) {
ZipArchiveEntry zae =
files.nextElement();
String zipname =
zae.getName();
if
(zipname.endsWith(".zip")) {
String
innerzip = StringUtils.removeEnd(zipname, ".zip");
File
innerfolder = new File(folder + File.separator + innerzip);
if
(!innerfolder.exists()) {
innerfolder.mkdirs();
}
ZipArchiveInputStream zais = new ZipArchiveInputStream(zf.getInputStream(zae),
"GBK", true);
FileOutputStream fos = null;
ZipArchiveEntry innerzae = null;
while
((innerzae = zais.getNextZipEntry()) != null) {
fos = new FileOutputStream(folder + File.separator + innerzip +
File.separator + innerzae.getName());
IOUtils.copy(zais, fos);
}
zais.close();
fos.flush();
fos.close();
} else {
ZipArchiveEntry packinfo = zf.getEntry(zipname);
String
filename = folder + File.separator + zipname;
FileOutputStream fos = new FileOutputStream(filename);
InputStream
is = zf.getInputStream(packinfo);
IOUtils.copy(is, fos);
is.close();
fos.flush();
fos.close();
}
}
zf.close();
|