Unzip a file with GZIPInputStream : GZIPInputStream « File « Java Tutorial






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

public class Main {
  public static void main(String[] args) throws Exception {
    int sChunk = 8192;

    String zipname = "a.txt.gz";
    String source = "a.txt";
    FileInputStream in = new FileInputStream(zipname);
    GZIPInputStream zipin = new GZIPInputStream(in);
    byte[] buffer = new byte[sChunk];
    FileOutputStream out = new FileOutputStream(source);
    int length;
    while ((length = zipin.read(buffer, 0, sChunk)) != -1)
      out.write(buffer, 0, length);
    out.close();
    zipin.close();
  }
}








11.65.GZIPInputStream
11.65.1.Create GZIPInputStream from FileInputStream
11.65.2.Unzip a file with GZIPInputStream
11.65.3.Ugzip using GZIPInputStream
11.65.4.Get Entry from a zip file