Here you can find the source of unGzip(final File compressedInputFile, final File outputDir)
Parameter | Description |
---|---|
compressedInputFile | the input .gz file |
outputDir | the output directory file. |
Parameter | Description |
---|
private static File unGzip(final File compressedInputFile, final File outputDir) throws IOException
//package com.java2s; //License from project: Apache License import java.io.*; import java.util.zip.GZIPInputStream; public class Main { /**//w w w. j a v a 2 s .c om * Ungzip an input file into an output file. * <p> * The output file is created in the output folder, having the same name * as the input file, minus the '.gz' extension. * * @param compressedInputFile the input .gz file * @param outputDir the output directory file. * @throws java.io.IOException * @throws java.io.FileNotFoundException * * @return File with the ungzipped content. */ private static File unGzip(final File compressedInputFile, final File outputDir) throws IOException { String uncompressedOutputFileName = null; if (compressedInputFile.getName().endsWith(".gz")) { uncompressedOutputFileName = compressedInputFile.getName().substring(0, compressedInputFile.getName().length() - 3); } else if (compressedInputFile.getName().endsWith(".tgz")) { uncompressedOutputFileName = compressedInputFile.getName().substring(0, compressedInputFile.getName().length() - 3) + "tar"; } else { throw new IllegalArgumentException("Compressed File:[" + compressedInputFile.getName() + "] Archive Type in unknown to this Utility Function!"); } // Un-Compress. final File outputFile = new File(outputDir, uncompressedOutputFileName); final GZIPInputStream in = new GZIPInputStream(new FileInputStream(compressedInputFile)); final FileOutputStream out = new FileOutputStream(outputFile); for (int c = in.read(); c != -1; c = in.read()) { out.write(c); } in.close(); out.close(); return outputFile; } }