How to Compress Files in Java – Zip Format

In this post we will see how to compress files in java using ZIP format.
Java provides a complete package java.util.zip to perform compression/decompression.

Steps to compress files in ZIP format

1. Create a ZipOutputStream using a FileOutputStream

2. Read all the Files that need to be zipped.

3. Iterate each file and use ZipEntry to add each file to Zip

Example

Lets zip the files from the below folder
How to Compress Files in Java

Output

How to Compress Files in Java