Here you can find the source of addFileToJar(File file, ZipOutputStream zipStream, String path)
private static void addFileToJar(File file, ZipOutputStream zipStream, String path) throws IOException
//package com.java2s; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; public class Main { private static void addFileToJar(File file, ZipOutputStream zipStream, String path) throws IOException { FileInputStream fin = new FileInputStream(file); int bufSize = 1024; byte ipBuf[] = new byte[bufSize]; int lenRead = 0; String filename = path + file.getName(); zipStream.putNextEntry(new ZipEntry(filename)); while ((lenRead = fin.read(ipBuf)) > 0) { zipStream.write(ipBuf, 0, lenRead); }//w w w. j a v a 2 s .c o m zipStream.closeEntry(); fin.close(); } }