How to Compress a File in GZIP Format

The below code would compress a specified file to GZip format. In the below example we have a text file in B drive under “Java” Folder and we are compressing and generating the GZip file in the same folder.