Ugzip using GZIPInputStream : GZIPInputStream « File « Java Tutorial






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

public class MainClass {

  public static void main(String[] args) {

    for (int i = 0; i < args.length; i++) {
      if (args[i].toLowerCase().endsWith(".gz")) {
        try {
          FileInputStream fin = new FileInputStream(args[i]);
          GZIPInputStream gzin = new GZIPInputStream(fin);
          FileOutputStream fout = new FileOutputStream(args[i].substring(0, args[i].length() - 3));
          for (int c = gzin.read(); c != -1; c = gzin.read()) {
            fout.write(c);
          }
          fout.close();
        } catch (IOException ex) {
          System.err.println(ex);
        }
      } else {
        System.err.println(args[i] + " does not appear to be a gzipped file.");
      }
    }
  }
}








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