Properties类的使用
Properties类的使用:
概述:java.util.Properties 继承于Hashtable ,来表示一个持久的属性集
特点:
1.Properties当成Map集合使用,键和值的类型为Object类型
2.Properties当成属性集使用,键和值的类型为String类型
构造方法:
public Properties() :创建一个空的属性列表。
成员方法:
- public Object setProperty(String key, String value) : 保存一对属性。
- public Set stringPropertyNames() :所有键的名称的集合。
- public String getProperty(String key) :使用此属性列表中指定的键搜索属性值。
- public void load(InputStream inStream): 从字节输入流中读取键值对。
注意:文本中的数据,必须是键值对形式,可以使用空格、等号、冒号等符号分隔。
- InputStream stream = PropertiesTest2.class.getClassLoader()
.getResourceAsStream(“db.properties”);//默认从src下面加载文件