Here you can find the source of gUnzip(File srcFile, File destFile)
Parameter | Description |
---|---|
srcFile | the source file. |
destFile | the destination file. |
Parameter | Description |
---|---|
IOException | error handling the files. |
public static void gUnzip(File srcFile, File destFile) throws IOException
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.GZIPInputStream; public class Main { /**/* ww w . j a va 2 s .c om*/ * GUnzips a source File to a destination File. * * @param srcFile the source file. * @param destFile the destination file. * @throws IOException error handling the files. */ public static void gUnzip(File srcFile, File destFile) throws IOException { FileOutputStream fos = null; GZIPInputStream zIn = null; InputStream fis = null; try { fos = new FileOutputStream(destFile); fis = new FileInputStream(srcFile); zIn = new GZIPInputStream(fis); copy(zIn, fos); } finally { if (fis != null) { fis.close(); } if (fos != null) { fos.close(); } if (zIn != null) { zIn.close(); } } } /** * Copies from the {@code InputStream} into the {@code OutputStream}. * * @param inputStream the {@code GZIPInputStream}. * @param outputStream the {@code OutputStream}. * @throws IOException error handling files. */ private static void copy(InputStream inputStream, OutputStream outputStream) throws IOException { byte[] buffer = new byte[8 * 1024]; int count = 0; do { outputStream.write(buffer, 0, count); count = inputStream.read(buffer, 0, buffer.length); } while (count != -1); } }