Apache commons compress | SevenZip unSevenZip Examples (.7z)

In this article we will go through some examples using Apache commons compress to create SevenZip (7zip or 7z) file & then un-seven-zip or unzip 7z file.

Dependency (maven, gradle, ivy etc.)

https://mvnrepository.com/artifact/org.apache.commons/commons-compress

You will also need below dependency in your project otherwise you might get exception java.lang.NoClassDefFoundError: org/tukaani/xz/FilterOptions

https://mvnrepository.com/artifact/org.tukaani/xz


Project structure (Basic maven project)

  • compress-me –> Folder to compress. Files range from 5 MB to 12 MB.
  • output –> output folder



Create SevenZip (7z) file from folders, sub folders

Unzip or UnSevenZip SevenZip (7z) file

Here is the output directory with created 7zip & unzipped folder.

Here is 7z file opened in 7z software.





Further Reading

Apache commons compress | TAR, GZip, BZip2, XZ, Snappy, Deflate Examples | un-GZip, UnTar Examples

Apache commons compress | Simplest zip, zip with directory, compression level, unzip

Leave a Reply

Your email address will not be published.