How to use ResourceBundle to avoid hard configuration paths in Java applications?

I would like to eliminate hard-coded path dependencies for configuration data in my Java applications, I understand that using the ResourceBundle will help me use the class loader to search for resources.

Can someone tell me how to replace a hard path with a resource (say the configuration data file .properties needed by the class) using ResourceBundle accordingly? A simple clear example, if possible, thanks to everyone.

+3
source share
4 answers

Prior to Java 6, ResourceBundle is usually resolved:

Java 6 ResourceBundle.Control, ResourceBundles, :

  • XML (. 2 Javadoc)

, .

+2
+3

ResourceBundle. Properties . , . , api.

+2

The Resource.getBundle (..) trick is using the class loader. You can load everything that is in your classpath by accessing it through this.getClass (). GetClassLoader (). Resource.getBundle (..) is a practical assistant to use in the resource / localization topic.

0
source

Source: https://habr.com/ru/post/1697742/


All Articles