You can't get the physical location from a ResourceBundle
, but if you know the path that was used to load it, then you can find out the physical location of that. Like this:
String resourceToLoad = "file";
URL url = this.getClassLoader().getResource(resourceToLoad);
ResourceBoundle bundle = ResourceBundle.getBundle(resourceToLoad);
The url
will have the physical location of the resource -- at least most of the time.
Remember that a ResourceBundle
can also be backed by a Java class rather than something like a properties file. ClassLoader.getResource
doesn't understand the mapping between ResourceBundle
and Java classes. If you want to be able to support those, you'll have to implement a similar algorithm to what ResourceBundle
does in order to search for classes that match it's scheme.