Here you can find the source of unzipFile(ZipFile archive, File targetFile, ZipEntry entry)
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. |
Parameter | Description |
---|---|
IOException | an exception |
private static void unzipFile(ZipFile archive, File targetFile, ZipEntry entry) throws IOException
//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(); } } } }