I’ve looked into the default Zip library in the JDK and Apache compression libs, but I’m not happy with them for a few reasons.
When working with Java unzip operations, I find these libraries overly complex and bloated, requiring 50+ lines of boilerplate code just to handle byte streams, close streams properly, and manage buffers.
I’m looking for a well-tested library with a clean API—something like:
Zipper.unzip(InputStream zipFile, File targetDirectory, String password = null);
Zipper.zip(File targetDirectory, String password = null);
Additionally, I’ve noticed that some libraries destroy file metadata, have poor password handling, and perform 2-3x slower than command-line zip tools on UNIX. Are there any better alternatives?
If you want seamless ZIP handling like normal file operations:
TFile zipFile = new TFile("example.zip");
TFile.unarchive(zipFile, new File("output-directory"));
- No manual stream handling
- Supports various archive formats (ZIP, TAR, 7z)
- Overkill if you just need basic ZIP handling
Maven Dependency:
<dependency>
<groupId>org.truezip</groupId>
<artifactId>truevfs-profile-default</artifactId>
<version>0.15.2</version>
</dependency>
Apache Commons is powerful, but requires slightly more code:
ZipArchiveInputStream zis = new ZipArchiveInputStream(new FileInputStream("example.zip"));
ArchiveEntry entry;
while ((entry = zis.getNextEntry()) != null) {
File outFile = new File("output-directory", entry.getName());
try (OutputStream os = new FileOutputStream(outFile)) {
IOUtils.copy(zis, os);
}
}
zis.close();
- High performance
- Supports multiple compression formats
- More boilerplate compared to Zip4j
Maven Dependency:
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.24.0</version>
</dependency>