Skip to main content

Compress a folder or directory to a zip file in Java

 Many times, for storage or transmission of files, we might be required to zip or compress a file. Compressing a file can reduce storage requirement and also transmission time and bandwidth.

Java provides a core library `` to make zipping and unzipping of files easy.

To zip an entire directory, we iterate through every files in the directory and add them to the output Zip file.

See below code on how to zip an entire directory or folder into a single zip file.