Skip to content

Instantly share code, notes, and snippets.

@team172011
Created October 17, 2019 15:53
Show Gist options
  • Save team172011/8fc836c607ec2ea7abdbdc1e43ce901a to your computer and use it in GitHub Desktop.
Save team172011/8fc836c607ec2ea7abdbdc1e43ce901a to your computer and use it in GitHub Desktop.
Unzip a zip file with all zip entries in java
private void unzipToParentDir(File file) throws IOException {
try (ZipFile zipFile = new ZipFile(file)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File entryDestination = new File(file.getParent(), entry.getName());
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
entryDestination.getParentFile().mkdirs();
InputStream in = zipFile.getInputStream(entry);
OutputStream out = new FileOutputStream(entryDestination);
IOUtils.copy(in, out);
IOUtils.closeQuietly(in);
out.close();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment