Compress Folder into zip file using Java

Example of compress a folder recursively into a zip file.

 

Example of output.

 

5 thoughts on “Compress Folder into zip file using Java

  1. This example has the same problem as many others I can find: It doesn’t work if there are no files in the source directory. In this case there’s never any entry created in the zip file, hence when you unzip you do not get the same result as the original source.

    When creating ZIP files I believe it is best practice *always* to create folder entries, even if you technically do not need them. This will avoid the problem. A folder entry in a ZIP file is simply something that ends with a ‘/’.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">