How to create a zip file in Java

In this tutorial, we show how to create a zip file from multiple files in Java.

1- ByteArrayOutputStream & ZipOutputStream

Using ByteArrayOutputStream and ZipOutputStream classes provided by the JDK, you can generate a zip file out of multiple files.

The following utility method accepts a list of File objects and generates a zip file as a byte array:

That’s it.

3.3 3 votes
Article Rating

Hussein Terek

Founder of, I have a passion in software engineering and everything related to java environment.

1 Comment
Newest Most Voted
Inline Feedbacks
View all comments
6 months ago

Thanks for post and exactly what is required.
Keep posting.