How to use resourcebundle to avoid hard coding configuration paths in Java applications?

I want to eliminate the dependency of hard coded path of configuration data in my java application. I know that using resourcebundle will help me find resources using classloader

Can someone tell me how to replace the hard coded path of resources (such as the. Properties configuration data file required by a class) by using resourcebundle appropriately? If possible, simple and clear examples, thank you

Solution

Prior to Java 6, resourcebundles typically allowed:

>Add strings from a set of localized property files using propertyresourcebundle > objects from a set of localized classes using listresourcebundle

Java 6 comes with resourcebundle Control class, which opens the door to other resourcebundles sources, such as:

>XML file (see example 2 in Javadoc) > database line

I hope this will help

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>