As usually I read resources from jar file as following:
getClassLoader().getResource(pTextPath + "/" + pLang +".xml");
I need to read all resources with certain name from known folder in jar file. E.g. read *.xml from
addon/resources/texts
Could I somehow get from jar files list of resources according to path and name template?
UPDATE: Exact duplication of Get a list of resources from classpath directory Please close the question.
When you build a java project and pack it into a jar (or a war), the files under the resources folder are included into the jar.
What you could do is to use getResourceAsStream() method with the directory path, and the input Stream will have all the files name from that dir. After that you can concat the dir path with each file name and call getResourceAsStream for each file in a loop.
A Java Archive, or JAR file, contains all of the various components that make up a self-contained, executable Java application, deployable Java applet or, most commonly, a Java library to which any Java Runtime Environment can link. There are two key benefits of using a JAR file.
CodeSource src = MyClass.class.getProtectionDomain().getCodeSource();
if (src != null) {
URL jar = src.getLocation();
ZipInputStream zip = new ZipInputStream(jar.openStream());
/* Now examine the ZIP file entries to find those you care about. */
...
}
else {
/* Fail... */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With