Copy directory from a jar file

Thanks for the solution! For others, the following doesn’t make use of the auxiliary classes (except for StringUtils) /I added extra information for this solution, check the end of the code, Zegor V/ public class FileUtils { public static boolean copyFile(final File toCopy, final File destFile) { try { return FileUtils.copyStream(new FileInputStream(toCopy), new FileOutputStream(destFile)); } … Read more

Junit + getResourceAsStream Returning Null

It’s not finding the resource on the classpath. If you are using junit and maven make sure the resources are copied on the target/test-classes by adding <include> file directive on <testResource> section You can also find out the location of your class in the file system by using this.getClass().getResource(“.”) and checking to see if the … Read more

How to list the files inside a JAR file?

CodeSource src = MyClass.class.getProtectionDomain().getCodeSource(); if (src != null) { URL jar = src.getLocation(); ZipInputStream zip = new ZipInputStream(jar.openStream()); while(true) { ZipEntry e = zip.getNextEntry(); if (e == null) break; String name = e.getName(); if (name.startsWith(“path/to/your/dir/”)) { /* Do something with this entry. */ … } } } else { /* Fail… */ } Note that … Read more

What is the difference between Class.getResource() and ClassLoader.getResource()?

Class.getResource can take a “relative” resource name, which is treated relative to the class’s package. Alternatively you can specify an “absolute” resource name by using a leading slash. Classloader resource paths are always deemed to be absolute. So the following are basically equivalent: foo.bar.Baz.class.getResource(“xyz.txt”); foo.bar.Baz.class.getClassLoader().getResource(“foo/bar/xyz.txt”); And so are these (but they’re different from the above): … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)