Use DeflaterOutputStream to zip : DeflaterOutputStream « File Input Output « Java






Use DeflaterOutputStream to zip

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

public class FileDeflater {
  public static void main(String[] args) throws Exception {
    FileInputStream fin = new FileInputStream("a.dat");
    FileOutputStream fout = new FileOutputStream("b.dat");
    DeflaterOutputStream dos = new DeflaterOutputStream(fout);
    for (int c = fin.read(); c != -1; c = fin.read()) {
      dos.write(c);
    }
    dos.close();
    fin.close();
  }
}

   
  








Related examples in the same category

1.Create a compressed data file by using a DeflaterOutputStream and then read that data through an InflaterInputStream.