Here you can find the source of addZipEntryRecursive(ZipOutputStream zipOut, File file, String prefix)
Parameter | Description |
---|---|
file | the file or directory to add to the output stream |
prefix | the prefix - is either blank or ends with a forwardslash e.g. "dir/" |
Parameter | Description |
---|---|
IOException | an exception |
private static void addZipEntryRecursive(ZipOutputStream zipOut, File file, String prefix) throws IOException
//package com.java2s; /******************************************************************************* * Copyright 2006, CHISEL Group, University of Victoria, Victoria, BC, Canada. * 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://w ww . ja va 2 s.c om * The Chisel Group, University of Victoria *******************************************************************************/ import java.io.File; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { /** * If the file is a file, it is added to the output stream with the given prefix. * If the file is a directory, it calls this method. * @param file the file or directory to add to the output stream * @param prefix the prefix - is either blank or ends with a forwardslash e.g. "dir/" * @throws IOException */ private static void addZipEntryRecursive(ZipOutputStream zipOut, File file, String prefix) throws IOException { if (file.isDirectory()) { String[] files = file.list(); for (String filename : files) { addZipEntryRecursive(zipOut, new File(file, filename), prefix + file.getName() + "/"); } } else { zipOut.putNextEntry(new ZipEntry(prefix + file.getName())); } } }