Java Unzip ZipEntry unzipFile(ZipFile archive, File targetFile, ZipEntry entry)

Here you can find the source of unzipFile(ZipFile archive, File targetFile, ZipEntry entry)

Description

unzip File

License

Open Source License

Parameter

Parameter Description
archive The zip file from which to extract.
targetFile The file to which the entry contents will be extracted.
entry The entry to extract.

Exception

Parameter Description
IOException an exception

Declaration

private static void unzipFile(ZipFile archive, File targetFile, ZipEntry entry) throws IOException 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2004, 2010 BREDEX GmbH.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors://from w w  w. j  a  va 2 s .c  o  m
 *     BREDEX GmbH - initial API and implementation and/or initial documentation
 *******************************************************************************/

import java.io.BufferedOutputStream;
import java.io.File;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

public class Main {
    /**
     * 
     * @param archive The zip file from which to extract.
     * @param targetFile The file to which the entry contents will be extracted.
     * @param entry The entry to extract.
     * @throws IOException
     */
    private static void unzipFile(ZipFile archive, File targetFile, ZipEntry entry) throws IOException {
        InputStream in = null;
        BufferedOutputStream out = null;
        try {
            in = archive.getInputStream(entry);
            out = new BufferedOutputStream(new FileOutputStream(targetFile));

            byte[] buffer = new byte[8192];
            int read;

            while (-1 != (read = in.read(buffer))) {
                out.write(buffer, 0, read);
            }
        } finally {
            if (in != null) {
                in.close();
            }
            if (out != null) {
                out.close();
            }
        }
    }
}

Related

  1. unzipEntry(ZipInputStream zis, File newFile)
  2. unzipEntry(ZipInputStream zis, File out)
  3. unzipEntry(ZipInputStream zis, File targetFile)
  4. unzipEntryToFolder(ZipEntry entry, InputStream zis, File destFolder)
  5. unZipFile(File destFile, ZipFile zipFile, ZipEntry entry)
  6. unzipSingleEntry(ZipInputStream zin, File toFile)