Java I/O How to - Unzip a file byte by byte








Question

We would like to know how to unzip a file byte by byte.

Answer

 //from  w w  w.j a  v a 2  s.c  om

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

public class Main {

  public static void main(String[] args) throws Exception {

    FileInputStream fin = new FileInputStream("a.dat");
    InflaterInputStream iis = new InflaterInputStream(fin);
    FileOutputStream fout = new FileOutputStream("b.dat");
    for (int c = iis.read(); c != -1; c = iis.read()) {
      fout.write(c);
    }
    fout.close();

  }
}