Here you can find the source of addToJar(JarOutputStream target, String pathInsideJar, File fentry)
public static void addToJar(JarOutputStream target, String pathInsideJar, File fentry) throws IOException
//package com.java2s; //License from project: Open Source License import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.jar.JarEntry; import java.util.jar.JarOutputStream; public class Main { public static void addToJar(JarOutputStream target, String pathInsideJar, File fentry) throws IOException { JarEntry entry = new JarEntry(pathInsideJar); entry.setTime(fentry.lastModified()); target.putNextEntry(entry);/*from w ww . j av a 2 s . c om*/ BufferedInputStream in = new BufferedInputStream(new FileInputStream(fentry)); byte[] buffer = new byte[1024]; while (true) { int count = in.read(buffer); if (count == -1) { break; } target.write(buffer, 0, count); } target.closeEntry(); in.close(); } }