Home » Zipping and Unzipping Files in Java

Zipping and Unzipping Files in Java

by Online Tutorials Library

Zipping and Unzipping Files in Java

ZIP is a common file format that compresses one or more files into a single location. It reduces the file size and makes it easier to transport or store. A recipient can unzip (or extract) a ZIP file after transport and use the file in the original format.

1. Single Zip file

Let’s see how we can zip one file in Java using the core Java libraries java.util.zip package.

ZipMultipleFiles.java

Output:

Zipping and Unzipping Files in Java

When we open the created zip file, we found the text file.

Zipping and Unzipping Files in Java

2. Multiple Zip Files

Let’s see how we can zip multiple files in Java using the core java libraries java.util.zip package.

ZipMultipleFiles.java

Output:

Zipping and Unzipping Files in Java

Let’s open the zip file.

Zipping and Unzipping Files in Java

3. Zip Directory

Let’s see how we can zip a directory in Java using the core libraries of java.util.zip package.

ZipDirectory.java

Output:

zipFiles contains following files:

Zipping and Unzipping Files in Java
Zipping and Unzipping Files in Java
Zipping and Unzipping Files in Java

4. Unzip a file

Let’s see how we can unzip a file in Java using the core libraries of java.util.zip package.

Unzip.java

Output:

Zipping and Unzipping Files in Java
Zipping and Unzipping Files in Java

Let’s open the web folder.

Zipping and Unzipping Files in Java


You may also like