Java Jar Zip File addToJar(JarOutputStream target, String pathInsideJar, File fentry)

Here you can find the source of addToJar(JarOutputStream target, String pathInsideJar, File fentry)

Description

add To Jar

License

Open Source License

Declaration

public static void addToJar(JarOutputStream target, String pathInsideJar, File fentry) throws IOException 

Method Source Code


//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();
    }
}

Related

  1. addJARs(File dir)
  2. addJars(File directory, boolean recursive)
  3. addJarsToClassPath(String jarPath)
  4. addJarToClasspath(File jarFile)
  5. addToJar(File source, JarOutputStream jarOutput)