Java讀取.properties配置文件

1.經過PropertiesLoaderUtils類來讀取

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.經過 java.util.ResourceBundle 類來讀取

 

//不須要加.properties後綴名,只須要文件名便可
//test. properties配置文件在com.test.config下面,則wei com/test/config/test
ResourceBundle resource = ResourceBundle.getBundle("test");
String test = resource.getString("test");
System.out.println("resource.test:"+test);
相關文章
相關標籤/搜索