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.

2.5 2 votes
Article Rating

Hussein Terek

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

You may also like...

guest
1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Atul
Atul
4 months ago

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