Allen Lantz Allen Lantz - 26 days ago 5
Java Question

How to export all files and folders in resources folder in java

How in java code do i copy everything from src/main/resources directory into the curent working directory?

My Files

Answer

I think what you are looking for is what was already asked and answered.

<pre> 
    java.util.jar.JarFile jar = new java.util.jar.JarFile(jarFile);
    java.util.Enumeration enumEntries = jar.entries();
    while (enumEntries.hasMoreElements()) {
        java.util.jar.JarEntry file = (java.util.jar.JarEntry) enumEntries.nextElement();
    java.io.File f = new java.io.File(destDir + java.io.File.separator + file.getName());
    if (file.isDirectory()) { // if its a directory, create it
        f.mkdir();
        continue;
        }
    java.io.InputStream is = jar.getInputStream(file); // get the input stream
    java.io.FileOutputStream fos = new java.io.FileOutputStream(f);
    while (is.available() > 0) {  // write contents of 'is' to 'fos'
        fos.write(is.read());
        }
        fos.close();
        is.close();
    }
</pre>

How to write a Java program which can extract a JAR file and store its data in specified directory (location)?

http://www.devx.com/tips/Tip/22124