Java Gunzip File gunzip(File gzippedFile, File destinationFile)

Here you can find the source of gunzip(File gzippedFile, File destinationFile)

Description

Uncompress gzipped files

License

Open Source License

Parameter

Parameter Description
gzippedFile The file to uncompress
destinationFile The resulting file

Exception

Parameter Description

Declaration

public static void gunzip(File gzippedFile, File destinationFile) throws IOException 

Method Source Code


//package com.java2s;
/*//from   w  ww.  jav a2 s . c om
 * Copyright (c) 2002-2006 The European Bioinformatics Institute, and others.
 * All rights reserved. Please see the file LICENSE
 * in the root directory of this distribution.
 */

import java.io.*;

import java.util.zip.*;

public class Main {
    /**
     * Uncompress gzipped files
     * @param gzippedFile The file to uncompress
     * @param destinationFile The resulting file
     * @throws java.io.IOException thrown if there is a problem finding or writing the files
     */
    public static void gunzip(File gzippedFile, File destinationFile) throws IOException {
        int buffer = 2048;

        FileInputStream in = new FileInputStream(gzippedFile);
        GZIPInputStream zipin = new GZIPInputStream(in);

        byte[] data = new byte[buffer];

        // decompress the file
        FileOutputStream out = new FileOutputStream(destinationFile);
        try {
            int length;
            while ((length = zipin.read(data, 0, buffer)) != -1)
                out.write(data, 0, length);
        } finally {
            out.close();

            zipin.close();
            in.close();
        }

    }
}

Related

  1. gunzip(File gzippedFile)
  2. gUnzip(File srcFile, File destFile)
  3. gunzip(InputStream packedData, OutputStream unpackedData)
  4. gunzip(String compressedStr)
  5. gunzip(String inFile, String outFile)