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:
When we open the created zip file, we found the text file.
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:
Let’s open the zip file.
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:
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:
Let’s open the web folder.