java 加载properties 文件


Properties properties = new Properties();
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("datasource.properties");
try {
properties.load(inputStream);
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(properties.getProperty("initialContextfactory"));
System.out.print(properties.getProperty("providerURL"));
System.out.print(properties.getProperty("dataSource"));

getClass().getClassLoader().//默认的是src文件夹下

getClass()//表示当前包中的文件


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM