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