ClassPathResource与PropertiesLoaderUtils

1.Springframeworks中的ClassPathResource类
用途:用来指定需要classLoader加载的资源(.properties/.yml)
ClassPathResource resource = new ClassPathResource( 资源的位置 )
2.Springframeworks里的PropertiesLoaderUtils 类
用途:用来获取资源文件的内容
Properties properties = PropertiesLoaderUtils.loadProperties( ClassPathResource的实体类 )
说明: Properties类 实现了Map接口,因此Properties类本质上是一种简单的Map容器

Properties类与properties关系:
Properties类本身表示了对一种Map结构的操作,properties文件本身就表示了一个“键值对”的集合
(1)Properties类可以通过绝对/相对路径方式加载properties文件(读取properties文件)
-->在spring框架中使用 ClassPathResource + PropertiesLoaderUtils
-->普通情况下使用Properties类中的load()方法 => Properties类对象.load(InputStream inStream)
(2)将程序中map集合通过Properties类保存为properties文件(保存为properties文件)
-->使用Properties类中的store()方法 => properties.store(OutputStream out, String comments)  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值