On the Internet I did not find any description or documentation of this function. What she does? And are there any other analogues of ResourceMap? For example, I heard somewhere that he can download resources, but can not jump to the folder above. Would you advise to work with it to download resources, or are there better analogues? And what options are there if I want to load resources from * .properties files
2 answers
If we are talking about a certain .properties file located in the src> main> resources directory, say config.properties with some content like:
key=value You can use the properties :
InputStream is = Thread.currentThread() .getContextClassLoader() .getResourceAsStream("config.properties"); Properties prop = new Properties(); prop.load(is); String key = prop.getProperty("key") Another option using ResourceBundle :
ResourceBundle rb = ResourceBundle.getBundle("config"); String key = rb.getString("key"); |
You did not find it because there is no such function in the java core. To download resources used
getClass().getResourceAsStream("/path/resource.xml"); or
Thread.currentThread().getContextClassLoader().getResource(resource); In general, there are different options.
- Could you add which options are the most effective and convenient when loading resources with reading from * .properties files. - Ersultan 4:39
|