Java Unzip File Example

Welcome to Java Unzip File Example. In the last post, we learned how to zip file and directory in java, here we will unzip the same zip file created from directory to another output directory.

Java Unzip File

To unzip a zip file, we need to read the zip file with ZipInputStream and then read all the ZipEntry one by one. Then use FileOutputStream to write them to file system.

We also need to create the output directory if it doesn’t exists and any nested directories present in the zip file.

Here is the java unzip file program that unzips the earlier created tmp.zip to output directory.

Once the program finishes, we have all the zip file contents in the output folder with same directory hierarchy.

Output of the above program is:

That’s all about java unzip file example.

By admin

Leave a Reply

%d bloggers like this: