I have a resources folder/package in the root of my project, I "don't" want to load a certain File. If I wanted to load a certain File, I would use class.getResourceAsStream and I would be fine!! What I actually want to do is to load a "Folder" within the resources folder, loop on the Files inside that Folder and get a Stream to each file and read in the content... Assume that the File names are not determined before runtime... What should I do? Is there a way to get a list of the files inside a Folder in your jar File? Notice that the Jar file with the resources is the same jar file from which the code is being run...
Thanks in advance...
Finally, I found the solution:
The second block just work when you run the application on IDE (not with jar file), You can remove it if you don't like that.
I know this is many years ago . But just for other people come across this topic. 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.Simple ... use OSGi. In OSGi you can iterate over your Bundle's entries with findEntries and findPaths.
Try the following.
Make the resource path
"<PathRelativeToThisClassFile>/<ResourceDirectory>"
E.g. if your class path is com.abc.package.MyClass and your resoure files are within src/com/abc/package/resources/:You can also use