public class ReadProperties {
/*
* 加载指定路径下的配置文件信息,并获得Properties对象
* (non-Javadoc)
* @see com.voole.interf.IProperties#getProperties()
* @return Properties对象
*/
public static Properties getProperties() {
return getProperties("/config.properties");
}
public static Properties getProperties(String path) {
InputStream inStream = ReadProperties.class.getResourceAsStream(path);
Properties prop = new Properties();
try {
if(inStream != null){
prop.load(inStream);
inStream.close();
}
} catch (IOException e) {
System.out.println("加载指定路径下的配置文件出错!"+e.getMessage());
}
return prop;
}
//使用
public static void main(String[] args) {
Properties pr = ReadProperties.getProperties();
System.out.println("mysql connection -- " + pr.getProperty("SQL_DRIVER"));
}
}
资源文件加载的的类
最新推荐文章于 2022-09-30 15:14:31 发布