public static void unzip2(String zipFilePath, String destinationPath) throws IOException {
try (ZipInputStream zis = new ZipInputStream(new BufferedInputStream(new FileInputStream(zipFilePath)))) {
String filename;
ZipEntry ze;
byte[] buffer = new byte[1024];
int count;
while ((ze = zis.getNextEntry()) != null) {
filename = ze.getName();
// Need to create directories if not exists, or
// it will generate an Exception...
if (ze.isDirectory()) {
File fmd = new File(destinationPath + filename);
fmd.mkdirs();
continue;
}
try (FileOutputStream fout = new FileOutputStream(destinationPath + filename)) {
while ((count = zis.read(buffer)) != -1) {
fout.write(buffer, 0, count);
}
}
zis.closeEntry();
}
}
}
반응형