This Java tip illustrates a method of compressing a file in the GZIP format. Gunzip is a universal format used by many applications to compress their files.

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 = > 0) {
            out.write(buf, 0, len);
        // Complete the GZIP file
    } catch (IOException e) {