Java基础_读取配置文件

[TOC]
读取配置文件
读取properties配置文件
properties类中的主要方法
1)getProperty(String key)
用指定的键在此属性列表中搜索属性。也就是通过参数key,得到key所对应的value。
2)load(InputStream inStream)
从输入流中读取属性列表(键和元素对)。以供getProperty( String key)来搜索。
3)setProperty(String key, String value)
调用Hashtable的方法put 。他通过调用基类的put方法来设置键-值对。
4)store(OutputStream out, String comments)
以适合使用load方法加载到Properties表中的格式,将此Properties表中的属性列表(键和元素对)写入输出流。与load方法相反,该方法将键-值对写入到指定的文件中去。
5)clear()
清除所有装载的键-值对。该方法在基类中提供
读取xml配置文件
Spring 读取properties文件
@ConfigurationProperties(prefix = "student")
@Value
Environment
详见项目springbootdemo
利用第三方配置工具owner读取配置文件
Last updated
Was this helpful?