The Java Developers Almanac 1.4


Order this book from Amazon.

   
Home > List of Packages > java.util.zip  [9 examples] > GZIP  [2 examples]

e452. Uncompressing a File in the GZIP Format

    try {
        // Open the compressed file
        String inFilename = "infile.gzip";
        GZIPInputStream in = new GZIPInputStream(new FileInputStream(inFilename));
    
        // Open the output file
        String outFilename = "outfile";
        OutputStream out = new FileOutputStream(outFilename);
    
        // Transfer bytes from the compressed file to the output file
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
    
        // Close the file and stream
        in.close();
        out.close();
    } catch (IOException e) {
    }

 Related Examples
e451. Compressing a File in the GZIP Format

See also: Checksums    ZIP   


© 2002 Addison-Wesley.