Breaking News
Home / Java / Java Tutorials / How to zip folder using Java?

How to zip folder using Java?

Zip Folder in JavaBuilding a utility like Winzip is easy in Java, thanks to package.

Basically we need to open a ZipOutputStream which is created on top of FileOutputStream, then loop through all the files in the folder. While looping, get the handle each of the file using FileInputStream and create a ZipEntry for each file. Then read the byte chucks of that file and write it to ZipOutputStream opened earlier. Once done writing all the files, close the flush and finally close the output stream. In result a zipped file will be created will all the files from the folder to be zipped.


Check Also

Have a Question

How to select a JVM Analyzing Tool?

A JVM monitoring tool also know as a Diagnostic might be needed to fine tune …

Advertisment ad adsense adlogger