Java reads .properties configuration file

1 The location and content of the configuration document

Add the configuration document test.properties under src/main/resources, and the document encoding format is utf-8.

 

 

 

2 Several ways to read documents

2.1 Reading through the PropertiesLoaderUtils class

 

 

import org.springframework.core.io.support.PropertiesLoaderUtils;

 

Properties properties = PropertiesLoaderUtils.loadAllProperties("test.properties");

String test = properties.getProperty("test");

System.out.println("properties.test:"+test);

 

2.2 Reading through the java.util.ResourceBundle class

//No need to add the .properties suffix, just the file name

//test.properties configuration file is under com.test.config, then wei com/test/config/test

ResourceBundle resource = ResourceBundle.getBundle("test");

String test = resource.getString("test");

System.out.println("resource.test:"+test);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325620331&siteId=291194637