文章目录
如题目所示,直接上方法,所有方法经过实践通过。
1.基于ClassLoder读取配置文件
注意:该方式只能读取类路径下的配置文件
filePath 为类路径下的相对路径,key为配置文件中要读取的key
filePath = "com/test/conf/conf_inner.propertier"
InputStream in = TestProperties.class.getClassLoader().getResourceAsStream(filePath);
Properties p = new Properties();
p.load(in);
String value = prop.getProperty(key)