How to GZip a File in Java

One of the most common compression algorithms out there is gzip. Therefore you are likely to need to compress files using gzip at some time or another. Below is an example of doing this in Java.

First create a FileInputStream from the file to be compressed. The data is read, and a compressed version of the contents are written to disk using GZIPOutputStream and FileOutputStream. The end result of this program is the creation of a gzipped copy of “sample_data_1.txt” on the local filesystem.

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=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">