I am familiar with obtaining the contents of a properties file given the name of the file, and obviously MyClass.class.getResource('*.properties') will not work, but how can I obtain a list of ALL the properties files located in the same package as my class?
Assuming that it's not JAR-packaged, you can use File#listFiles()
for this. Here's a kickoff example:
String path = MyClass.class.getResource("").getPath();
File[] propertiesFiles = new File(path).listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.endsWith(".properties");
}
});
If it's JAR-packaged, then you need a bit more code, to start with JarFile
API. You can find another example in this answer.
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