public static void zipDir(File directory, File zipfile) throws IOException {
		URI base = directory.toURI();
		Deque<File> queue = new LinkedList<File>();
		queue.push(directory);
		OutputStream out = new FileOutputStream(zipfile);
		Closeable res = out;
		try {
			ZipOutputStream zout = new ZipOutputStream(out);
			res = zout;
			while (!queue.isEmpty()) {
				directory = queue.pop();
				for (File kid : directory.listFiles()) {
					String name = base.relativize(kid.toURI()).getPath();
					if (kid.isDirectory()) {
						queue.push(kid);
						name = name.endsWith("/") ? name : name + "/";
						zout.putNextEntry(new ZipEntry(name));
					} else {
						zout.putNextEntry(new ZipEntry(name));
						copy(kid, zout);
						zout.closeEntry();
					}
				}
			}
		} finally {
			res.close();
		}
	}
public static void zipDir(File directory, File zipfile) throws IOException {
		URI base = directory.toURI();
		Deque<File> queue = new LinkedList<File>();
		queue.push(directory);
		OutputStream out = new FileOutputStream(zipfile);
		Closeable res = out;
		try {
			ZipOutputStream zout = new ZipOutputStream(out);
			res = zout;
			while (!queue.isEmpty()) {
				directory = queue.pop();
				for (File kid : directory.listFiles()) {
					String name = base.relativize(kid.toURI()).getPath();
					if (kid.isDirectory()) {
						queue.push(kid);
						name = name.endsWith("/") ? name : name + "/";
						zout.putNextEntry(new ZipEntry(name));
					} else {
						zout.putNextEntry(new ZipEntry(name));
						copy(kid, zout);
						zout.closeEntry();
					}
				}
			}
		} finally {
			res.close();
		}
	}
public static void zipDir ( File directory , File zipfile ) throws IOException { URI base = directory . toURI ( ) ; Deque < File > queue = new LinkedList < File > ( ) ; queue . push ( directory ) ; OutputStream out = new FileOutputStream ( zipfile ) ; Closeable res = out ; try { ZipOutputStream zout = new ZipOutputStream ( out ) ; res = zout ; while ( ! queue . isEmpty ( ) ) { directory = queue . pop ( ) ; for ( File kid : directory . listFiles ( ) ) { String name = base . relativize ( kid . toURI ( ) ) . getPath ( ) ; if ( kid . isDirectory ( ) ) { queue . push ( kid ) ; name = name . endsWith ( "/" ) ? name : name + "/" ; zout . putNextEntry ( new ZipEntry ( name ) ) ; } else { zout . putNextEntry ( new ZipEntry ( name ) ) ; copy ( kid , zout ) ; zout . closeEntry ( ) ; } } } } finally { res . close ( ) ; } }
src: http://stackoverflow.com/questions/1399126/java-util-zip-recreating-directory-structure
src : http : // stackoverflow . com / questions / 1399126 / java - util - zip - recreating - directory - structure