Here you can find the source of zipFiles(File file, JarOutputStream jos, String pathName)
private static void zipFiles(File file, JarOutputStream jos, String pathName) throws Exception
//package com.java2s; // %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; public class Main { private static int bufSize = 2048; private static void zipFiles(File file, JarOutputStream jos, String pathName) throws Exception { String fileName = pathName + file.getName(); if (file.isDirectory()) { fileName = fileName + "/"; jos.putNextEntry(new JarEntry(fileName)); String fileNames[] = file.list(); if (fileNames != null) { for (int i = 0; i < fileNames.length; i++) { zipFiles(new File(file, fileNames[i]), jos, fileName); }//from w ww . j ava2s . c om jos.closeEntry(); } } else { JarEntry jarEntry = new JarEntry(fileName); BufferedInputStream in = new BufferedInputStream(new FileInputStream(file)); jos.putNextEntry(jarEntry); byte[] buf = new byte[bufSize]; int len; while ((len = in.read(buf)) >= 0) { jos.write(buf, 0, len); } in.close(); jos.closeEntry(); } } }