Here you can find the source of copyFromZip(ZipFile zipFile, String locationInBundle, File destination)
private static void copyFromZip(ZipFile zipFile, String locationInBundle, File destination) throws IOException
//package com.java2s; /******************************************************************************* * Copyright (c) 2013 Red Hat, Inc./* w w w . ja va 2 s . co m*/ * Distributed under license by Red Hat, Inc. All rights reserved. * This program is 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: * Red Hat, Inc. - initial API and implementation ******************************************************************************/ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.channels.Channels; import java.nio.channels.FileChannel; import java.util.Enumeration; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; public class Main { private static void copyFromZip(ZipFile zipFile, String locationInBundle, File destination) throws IOException { Enumeration<? extends ZipEntry> entries = zipFile.entries(); while (entries.hasMoreElements()) { ZipEntry zipEntry = entries.nextElement(); if (zipEntry.getName().startsWith(locationInBundle)) { String path = zipEntry.getName().substring(locationInBundle.length()); File file = new File(destination, path); if (!zipEntry.isDirectory()) { createFileFromZipFile(file, zipFile, zipEntry); } else { if (!file.exists()) { file.mkdir(); } } } } } private static void createFileFromZipFile(File file, ZipFile zipFile, ZipEntry zipEntry) throws IOException { if (!file.getParentFile().exists() && !file.getParentFile().mkdirs()) { throw new IOException("Can not create parent directory for " + file.toString()); } file.createNewFile(); FileOutputStream fout = null; FileChannel out = null; InputStream in = null; try { fout = new FileOutputStream(file); out = fout.getChannel(); in = zipFile.getInputStream(zipEntry); out.transferFrom(Channels.newChannel(in), 0, Integer.MAX_VALUE); } finally { if (out != null) out.close(); if (in != null) in.close(); if (fout != null) fout.close(); } } }