The Java Developers Almanac 1.4


Order this book from Amazon.

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

e451. Compressing a File in the GZIP Format

    try {
        // Create the GZIP output stream
        String outFilename = "outfile.gzip";
        GZIPOutputStream out = new GZIPOutputStream(new FileOutputStream(outFilename));
    
        // Open the input file
        String inFilename = "infilename";
        FileInputStream in = new FileInputStream(inFilename);
    
        // Transfer bytes from the input file to the GZIP output stream
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) {
            out.write(buf, 0, len);
        }
        in.close();
    
        // Complete the GZIP file
        out.finish();
        out.close();
    } catch (IOException e) {
    }

 Related Examples
e452. Uncompressing a File in the GZIP Format

See also: Checksums    ZIP   


© 2002 Addison-Wesley.