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);

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM