I have recently converted an existing Java-application into a Maven-application which is generating a MyJar.jar file. Also I've included the application's resource xml files inside a folder named "MyXml" and packaged it in that jar.
Now I need to read that list of xml files within that folder inside the jar and iterate over the files. I am using linux environment, and my java code is getting Null pointer
exception while trying to access that folder inside the jar.
The folder path in the Jar is :
String folderPath = "app/tools/Tool1/MyJar.jar/MyXml/";
The java code which is throwing exception is:
final File folder = new File(folderPath);
for (final File fileEntry : folder.listFiles()) {
if (fileEntry.getName().toLowerCase().endsWith(".xml")) {
System.out.println("Xml File name : "+fileEntry.getName());
}
}
In the for-loop , "folder" object is getting null and throwing exception. Can't we mention a file-path inside a "jar" using java?
I saw some examples from Here, but there it's reading only particular file from jar, not the list of files. Any suggestion will be helpful.