FAQ

Java

JSP

Servlet


Advertisement



How to uncompress a file in the gzip format?

This example decompresses a gzip compressed file with java.util.zip.GZIPInputStream.

public static boolean Uncompression(String infname, String outfname){
   
    GZIPInputStream in = null;
    OutputStream out = null;
   
    try {

        in = new GZIPInputStream(new FileInputStream(infname));
        out = new FileOutputStream(outfname);

        byte[] buf = new byte[65536];
        int len;
        while ((len = in.read(buf)) != -1) {
            out.write(buf, 0, len);
        }

        in.close();
        out.close();
        return true;
    } catch (IOException e) {
        if ( in != null ) {
            try {
                in.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        if ( out != null ) {
            try {
                out.close();
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
        return false;
    }
}


Printer-friendly version Printer-friendly version | Send this 
article to a friend Mail this to a friend

Previous Next vertical dots separating previous/next from contents/index/pdf Contents

  |   |