Zip a file with GZIPOutputStream : GZIPOutputStream « File « Java Tutorial






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

public class Main {

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

    String zipname = "a.gz";
    FileOutputStream out = new FileOutputStream(zipname);
    GZIPOutputStream zipout = new GZIPOutputStream(out);
    byte[] buffer = new byte[sChunk];

    FileInputStream in = new FileInputStream(args[0]);
    int length;
    while ((length = in.read(buffer, 0, sChunk)) != -1)
      zipout.write(buffer, 0, length);
    in.close();
    zipout.close();

  }
}








11.66.GZIPOutputStream
11.66.1.GZIP compress by GZIPOutputStream
11.66.2.Zip a file with GZIPOutputStream