Java Unzip File uncompress(File zipFile, File folder)

Here you can find the source of uncompress(File zipFile, File folder)

Description

uncompress

License

Open Source License

Declaration

public static void uncompress(File zipFile, File folder) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

public class Main {
    public static void uncompress(File zipFile, File folder) {
        try (FileInputStream inputStream = new FileInputStream(zipFile)) {
            ZipInputStream zip = new ZipInputStream(inputStream);
            ZipEntry entry;/*www  . ja va 2 s  .  c  o m*/
            byte[] buffer = new byte[1024];
            while ((entry = zip.getNextEntry()) != null) {
                File file = new File(folder, entry.getName());

                File entryfolder = file.getParentFile();
                if (!entryfolder.exists()) {
                    entryfolder.mkdirs();
                }

                try (FileOutputStream fos = new FileOutputStream(file)) {
                    int len;
                    while ((len = zip.read(buffer)) > 0) {
                        fos.write(buffer, 0, len);
                    }
                }
            }
            zip.close();
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage(), e);
        }
    }
}

Related

  1. decompressFile(File destFile, ZipInputStream zis)
  2. decompressFile(final File toDecompress, final File destinationFile)
  3. decompressFile(String inName)
  4. decompressGzip(File src, File trgt)
  5. uncompress(ByteArrayInputStream bais)
  6. uncompress(final InputStream inputStream)
  7. uncompress(final String zipFileName, final String directory)
  8. uncompress(String chemin, String tempPrefix)
  9. uncompress(String compressedValue)