Here you can find the source of unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDirectory)
private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDirectory)
//package com.java2s; /******************************************************************************* * Copyright (c) 2007-2017 Red Hat, Inc. * Distributed under license by Red Hat, Inc. All rights reserved. * This program is made available under the terms of the * Eclipse Public License v 1.0 which accompanies this distribution, * and is available at http://www.eclipse.org/legal/epl-v10.html * * Contributor:/*from ww w . j av a 2s . co m*/ * Red Hat, Inc. - initial API and implementation ******************************************************************************/ import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class Main { private static void unzipEntry(ZipFile zipfile, ZipEntry entry, File outputDirectory) { if (entry.isDirectory()) { createDirectory(new File(outputDirectory, entry.getName())); return; } File outputFile = new File(outputDirectory, entry.getName()); if (!outputFile.getParentFile().exists()) { createDirectory(outputFile.getParentFile()); } BufferedInputStream inputStream = null; BufferedOutputStream outputStream = null; try { inputStream = new BufferedInputStream( zipfile.getInputStream(entry)); outputStream = new BufferedOutputStream(new FileOutputStream( outputFile)); copy(inputStream, outputStream, 1024); } catch (IOException ex) { } finally { try { outputStream.close(); } catch (Exception ex) { } try { inputStream.close(); } catch (Exception ex) { } } outputFile.setExecutable(true); outputFile.setReadable(true); outputFile.setWritable(true); } public static void createDirectory(File directory) { if (!directory.exists()) { directory.mkdirs(); } } private static void copy(InputStream inputStream, OutputStream outputStream, int bufferSize) throws IOException { byte[] buffer = new byte[bufferSize]; int length; while ((length = inputStream.read(buffer)) > 0) { outputStream.write(buffer, 0, length); } } }