What is a good Java library for unzipping files?

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?

You’re right—JDK’s ZipInputStream is too verbose. Zip4j offers a modern API and supports encryption:

ZipFile zipFile = new ZipFile("example.zip", "password".toCharArray());
zipFile.extractAll("output-directory");
  • :heavy_check_mark: Supports passwords & AES encryption
  • :heavy_check_mark: Simple API
  • :x: Adds a dependency (net.lingala.zip4j)

:pushpin: Maven Dependency:

<dependency>
    <groupId>net.lingala.zip4j</groupId>
    <artifactId>zip4j</artifactId>
    <version>2.11.5</version>
</dependency>

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

:pushpin: 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

:pushpin: Maven Dependency:

<dependency>
    <groupId>org.apache.commons</groupId>
    <artifactId>commons-compress</artifactId>
    <version>1.24.0</version>
</dependency>