How to read gzip text file in Java

In the post How to read Text Files in Java. So how to read it if a text file is gzipped. Again Decorator Pattern comes to the rescue. We do minor changes to the program. Instead of using FileReader, we update the code as following

The highlighted lines shows the change. We get the InputStream and add GZipInputStream over it to deflate the compression. We use Reader as we know we shall be processing a text file. This is the only change needed to process gzipped files.

Everything Together

Leave a Reply

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