Properties与ResourceBundle的使用方法
2019-07-22 18:54
169 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/MeatLoveJK/article/details/96883860
一、Properties的使用
步骤:
1.在项目中创建一个File文件 --> 名字.properties (后缀名一定要写对)
2.创建一个properties的对象:Properties pro = new Properties();
3.:Thread.currentThread().getContextClassLoader().getResourceAsStream(文件名.properties);
该方法返回一个输入流对象in。
4.pro.load(in);加载输入流
总结:properties里面的值是按照键-值对的形式存放的。
所以可以调用 pro.getProperty(key)来获得值。默认是String类型的。
写properties时:如:
drivername = com.mysql.jdbc.Driver
url = jdbc:mysql://localhost:3306/day22?useUnicode=true&characterEncoding=UTF8
username = root
password = zxh86356449
注意:没有引号,没有分号!
二、ResourceBundle的使用
步骤:
1.ResourceBundle rb = ResourceBundle.getBundle(文件名);
通过这一步就可以使用该文件了。
注意:文件名没有后缀的.properties。
相关文章推荐
- 使用J2SE API读取Properties文件的六种方法
- 使用J2SE API读取Properties文件的六种方法(1)
- 如何使用android.os.SystemProperties的方法
- 使用J2SE API读取Properties文件的六种方法
- 使用J2SE API读取Properties文件的六种方法
- 使用Properties的load方法加载属性信息
- Hibernate的Query的setProperties(Map map)方法的使用
- 使用J2SE API读取Properties文件的六种方法
- Java中使用ResourceBundle访问资源文件(properties文件)
- Java中使用ResourceBundle访问资源文件(properties文件)
- 使用JAVA读写Properties属性文件的方法详解
- Spring配置文件中使用ref local与ref bean的区别. 在ApplicationResources.properties文件中,使用<ref bean>与<ref local>方法如下
- 关于BeanUtils.copyProperties( )方法的使用
- 使用ResourceBundle国际化资源文件读取properties详解
- ResourceBundle 的一种使用方法
- 使用J2SE API读取Properties文件的六种方法
- 使用J2SE API读取Properties文件的六种方法
- Java中使用ResourceBundle访问资源文件(properties文件)
- 使用J2SE API读取Properties文件的六种方法
- 比较常用的Properties配置文件的使用方法示例