Java Unzip File decompressFile(String inName)

Here you can find the source of decompressFile(String inName)

Description

decompress File

License

Apache License

Declaration

public static void decompressFile(String inName) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.File;
import java.io.FileInputStream;

import java.io.FileOutputStream;
import java.util.zip.GZIPInputStream;

public class Main {
    private static Integer BUFF_SIZE = 1024;

    public static void decompressFile(String inName) {
        try {/*  w  w w  .  j  a  v  a2 s  .  c o m*/
            File f = new File(inName);
            String outName = inName.replace(".gz", "");
            File fout = new File(outName);

            if (fout.exists()) {
                System.out.println("Unzip File Already Exist:" + outName);
                System.out.println("Rename:" + outName + "(1)");
                fout = new File(outName + "(1)");
            }
            FileInputStream is = new FileInputStream(f);
            FileOutputStream os = new FileOutputStream(fout);
            GZIPInputStream gs = new GZIPInputStream(is);
            int len;
            byte buf[] = new byte[BUFF_SIZE];
            while ((len = gs.read(buf, 0, BUFF_SIZE)) != -1) {
                os.write(buf, 0, len);
            }
            is.close();
            os.close();
            gs.close();
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}

Related

  1. decompress(String filepath, File outpathdir, String includes)
  2. decompress(String zipFile, String targetPath)
  3. decompresses(File file, File destinationDirectory)
  4. decompressFile(File destFile, ZipInputStream zis)
  5. decompressFile(final File toDecompress, final File destinationFile)
  6. decompressGzip(File src, File trgt)
  7. uncompress(ByteArrayInputStream bais)
  8. uncompress(File zipFile, File folder)
  9. uncompress(final InputStream inputStream)