GZIP File in Java – Compression And Decompression

In this post we’ll see how to compress and decompress a file in Java using GZIP format. Using GZIP you can only compress a single file not multiple files in a directory.

See the procedure of creating a tar archive to gzip multiple files in this post- GZIP Multiple Files in Java Creating Tar Archive

Java GZIP example- Compress and decompress file

GZIP compression– For compressing a file GZIPOutputStream is used. You need to read a file using InputStream and write it to the GZIPOutputStream to get a GZIP format file.

GZIP decompression– For decompressing a file GZIPInputStream is used. You need to read a file from GZIPInputStream and write it to the output stream to get a decompressed file.

That’s all for the topic GZIP File in Java – Compression And Decompression. If something is missing or you have something to share about the topic please write a comment.

You may also like

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.