首页 > 其他 > 详细

配置文件的读取

时间:2019-01-22 13:43:49      阅读:150      评论:0      收藏:0      [点我收藏+]

(1)配置文件放在项目的根目录下

Properties properties = new Properties();
InputStream is = new FileInputStream("config.properties");

// 导入输入流
properties.load(is);

// 读取
driverClass = properties.getProperty("driverClass");
url = properties.getProperty("url");
username = properties.getProperty("username");
password = properties.getProperty("password");

 

(2)配置文件放在src目录下

Properties properties = new Properties();
InputStream is = JDBCutils.class.getClassLoader().getResourceAsStream("config.properties");

// 导入输入流
properties.load(is);

// 读取
driverClass = properties.getProperty("driverClass");
url = properties.getProperty("url");
username = properties.getProperty("username");
password = properties.getProperty("password");

 

配置文件的读取

原文:https://www.cnblogs.com/chichung/p/10303205.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!