GZIPInputStream java example

If you have a gzip file and you want decompress it you can use this code :

 

byte[] buffer = new byte[1024];

GZIPInputStream gzis = null;

FileOutputStream out = null;

     try{

         gzis = new GZIPInputStream(new FileInputStream(INPUT_GZIP_FILE));

         out =   new FileOutputStream(OUTPUT_FILE);

        int len;

        while ((len = gzis.read(buffer)) > 0) {

               out.write(buffer, 0, len);

        }

    }catch(IOException ex){

       ex.printStackTrace();

    } finally {

          if (gzis!=null)   gzis.close();

          if (out!=null) out.close();

      }

   }