引子:如图所示,此配置文件是如何读取到的呢?其里面配的值,又是如何得到的呢?
1、怎么读取配置文件(比如 resources下的smart.properties)?
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); //此处fileName是smart.properties
Properties properties = new Properties(); //java.util.Properties
properties.load(properties);
2、怎么获取配置文件(smart.properties)里的值(如 smart.framework.jdbc.driver=com.mysql.jdbc.Driver)?
String key = "smart.framework.jdbc.driver";
if(properties.containsKey(key)){
properties.getProperties(key);
}