Last Updated:

Archive and decompress a GZIP file in Java

Here is an example of a simple Java program showing how to compress a single file into GZIP format and then decompress it.

If a non-GZIP file is passed to the decompression method, an exception will be thrown: