How to unzip files in java

H

In this post, I will show you how to unzip a .zip-file in java.

First, add the Maven dependency:

<dependency>
    <groupId>org.apache.ant</groupId>
    <artifactId>ant-compress</artifactId>
    <version>1.4</version>
</dependency>

Then, you need to add the following code to your method where you want to unzip.

Unzip unzipper = new Unzip();
try {
    unzipper.setSrc(new File("test.zip"));
    unzipper.setDest("/myFolderToExtract");
    unzipper.execute();
} catch (IOException e) {
    e.printStackTrace();
}

Add comment

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Tag Cloud

Categories