Java Utililty Methods Unzip File

List of utility methods to do Unzip File

Description

The list of methods to do Unzip File are organized into topic(s).

Method

voidunzip(File file, String targetDirectory)
unzip
System.out.println("Extracting: " + file);
ZipFile zipFile = new ZipFile(file);
Enumeration<?> entries = zipFile.entries();
String stripName = file.getName();
int i = stripName.lastIndexOf('.');
if (i > 0) {
    stripName = stripName.substring(0, i);
while (entries.hasMoreElements()) {
    ZipEntry entry = (ZipEntry) entries.nextElement();
    String entryName = entry.getName();
    if (entryName.startsWith(stripName + "/") || entryName.startsWith(stripName + "\\")) {
        entryName = entryName.substring(stripName.length() + 1);
    if (entry.isDirectory()) {
        File dir = new File(targetDirectory, entryName);
        dir.mkdirs();
        continue;
    copyInputStream(zipFile.getInputStream(entry),
            new BufferedOutputStream(new FileOutputStream(new File(targetDirectory, entryName))));
zipFile.close();
voidunzip(File fileToUnzip, File destinationDirectory)
unzip
if (!destinationDirectory.exists()) {
    destinationDirectory.mkdirs();
} else {
    if (destinationDirectory.isFile()) {
        destinationDirectory = destinationDirectory.getParentFile();
try (ZipInputStream zis = new ZipInputStream(new FileInputStream(fileToUnzip))) {
...
voidunZip(File inFile, File unzipDir)
Given a File input it will unzip the file in a the unzip directory passed as the second parameter
Enumeration<? extends ZipEntry> entries;
ZipFile zipFile = new ZipFile(inFile);
try {
    entries = zipFile.entries();
    while (entries.hasMoreElements()) {
        ZipEntry entry = entries.nextElement();
        if (!entry.isDirectory()) {
            InputStream in = zipFile.getInputStream(entry);
...
voidunzip(File input)
unzip
FileInputStream fis = null;
ZipInputStream zis = null;
ZipEntry entry = null;
try {
    fis = new FileInputStream(input);
    zis = new ZipInputStream(fis);
    while ((entry = zis.getNextEntry()) != null) {
        File targetFile = new File(entry.getName());
...
voidunzip(File input, File outputDir)
unzip
try {
    if (!outputDir.exists())
        outputDir.mkdir();
    ZipFile zipFile = new ZipFile(input);
    Enumeration e = zipFile.entries();
    while (e.hasMoreElements()) {
        ZipEntry entry = (ZipEntry) e.nextElement();
        File destinationFilePath = new File(outputDir, entry.getName());
...
voidunzip(File input, File outputDirectory)
Unzips the file input and places its content in outputDirectory.
ZipFile zip = new ZipFile(input);
for (Enumeration<? extends ZipEntry> entries = zip.entries(); entries.hasMoreElements();) {
    ZipEntry entry = entries.nextElement();
    if (entry.isDirectory()) {
        File dir = new File(outputDirectory, entry.getName());
        dir.mkdirs();
    } else {
        File out = new File(outputDirectory, entry.getName());
...
voidunzip(File inputFile, File outputDir)
unzip
ZipInputStream zis = new ZipInputStream(new FileInputStream(inputFile));
ZipEntry ze = zis.getNextEntry();
while (ze != null) {
    String entryName = ze.getName();
    File f = new File(outputDir + File.separator + entryName);
    f.getParentFile().mkdirs();
    FileOutputStream fos = new FileOutputStream(f);
    int len;
...
voidunzip(File inputFile, File unzipDestFolder)
unzip
ZipFile zipFile = null;
InputStream inputStream = null;
try {
    zipFile = new ZipFile(inputFile);
    Enumeration<? extends ZipEntry> oEnum = zipFile.entries();
    while (oEnum.hasMoreElements()) {
        ZipEntry zipEntry = oEnum.nextElement();
        File file = new File(unzipDestFolder, zipEntry.getName());
...
voidunzip(File intoFolder, ZipFile zipFile)
unzip
Enumeration<?> enu = zipFile.entries();
while (enu.hasMoreElements()) {
    ZipEntry zipEntry = (ZipEntry) enu.nextElement();
    String name = zipEntry.getName();
    String nameFixed = name.replaceAll("\\\\", "/");
    File file = new File(intoFolder, nameFixed);
    if (nameFixed.endsWith("/")) {
        file.mkdirs();
...
voidunzip(File jar, File target)
unzip
final ZipFile in = new ZipFile(jar);
final Enumeration<? extends ZipEntry> entries = in.entries();
while (entries.hasMoreElements()) {
    final ZipEntry entry = entries.nextElement();
    if (!entry.isDirectory()) {
        final File file = new File(target, entry.getName());
        file.getParentFile().mkdirs();
        copy(in.getInputStream(entry), new FileOutputStream(file), true);
...