GZIPOutputStream: write(byte[] buf, int off, int len) : GZIPOutputStream « java.util.zip « Java by API






GZIPOutputStream: write(byte[] buf, int off, int len)

 

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();

  }
}

   
  








Related examples in the same category

1.new GZIPOutputStream(OutputStream out)