extract Jar Entry - Java Reflection

Java examples for Reflection:Jar

Description

extract Jar Entry

Demo Code


import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class Main{
    public static String extractJarEntry(String outPath, JarFile jarFile,
            JarEntry entry) throws Exception {
        outPath = outPath.endsWith("/") ? outPath : outPath + '/';
        File file = new File(outPath + entry.getName());
        if (!file.exists()) {
            if (entry.isDirectory()) {
                file.mkdirs();//from   w  w w  .j av  a  2 s .  c o m
            } else {
                file.getParentFile().mkdirs();
                InputStream is = jarFile.getInputStream(entry);
                IOUtil.copy(is, new FileOutputStream(file));
            }
        }
        return file.getCanonicalPath();

    }
}

Related Tutorials