使用ResourceBundle一行代码读取Properties文件

使用ResourceBundle一行代码读取Properties文件,代码如下:

        ResourceBundle conf = ResourceBundle.getBundle("config");

下面详情说明:

1. config.properties文件,放在资源目录下,例如resource/config.properties

文件内容为:

wxtoken=123456
wxappid=wxe234detre7c0

2.使用 ResourceBundle解析config.properties文件的代码如下:

ResourceBundle conf = ResourceBundle.getBundle("config");

System.out.println(conf.getString("wxtoken"));

System.out.println(conf.getString("wxappid"));

3.运行后在控制台输出如下信息: 

123456
wxe234detre7c0

下载源码 

猜你喜欢

转载自blog.csdn.net/jlq_diligence/article/details/89603386