How to Extract gz/GZIP files in java?

Here is a simple java GZIP example program showing how can we decompress the GZIP or how to Extract gz/GZIP files in java

package com.nourit.javaIO;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.zip.GZIPInputStream;

public class FileDecompressioninGZIP {
  private static final String GZIP_INPUT_FILE = "D:/tmp/NOUR-IT.gz";
  private static final String DEST_FILE = "D:/tmp/NOUR-IT.txt";
   public static void main( String[] args )
   {
     byte[] buffer = new byte[1024];
        try{
            GZIPInputStream gZIPInputStream = new GZIPInputStream(new FileInputStream(GZIP_INPUT_FILE));
            FileOutputStream fileOutputStream = new FileOutputStream(DEST_FILE);
            int len;
            while ((len = gZIPInputStream.read(buffer)) > 0) {
            	fileOutputStream.write(buffer, 0, len);
            }

            gZIPInputStream.close();
            fileOutputStream.close();

            System.out.println("The " + DEST_FILE + " Extracted");

        } catch(IOException ex){
            ex.printStackTrace();
        }
     }
}

 

NOUR-IT

IT Training Center for Java and Web technology. If you enjoy and like our tutorials and believe in our mission, Please Subscribe us on Youtube and follow us on Twitter, or befriend us on Facebook or Google Plus.

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert.

*