重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

java读取properties文件

文件名为db.properties

麻山ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18980820575(备注:SSL证书合作)期待与您的合作!

第一种: 通过ResourceBundle获取
ResourceBundle bunble = ResourceBundle.getBundle("db");
driver = bunble.getString("driver");
url = bunble.getString("url");
username = bunble.getString("username");
password = bunble.getString("password");

第二种:通过类加载器获取
// 1. 通过当前类获取类加载器   访问方式: 类型.class.getClassLoader()
ClassLoader classLoader = JDBCUtils_V3.class.getClassLoader();
// 2. 通过类类加载器获取一个输入流
InputStream is = classLoader.getResourceAsStream("db.properties");
// 3. 创建properties对象
Properties p = new Properties();
// 4. 加载输入流
p.load(is);
// 5. 获取相关参数的值
driver = p.getProperty("driver");
url = p.getProperty("url");
username = p.getProperty("username");
password = p.getProperty("password");

网站栏目:java读取properties文件
链接地址:http://cqcxhl.cn/article/ijdghi.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP