9.6.3 Property Map
属性映射(property map)是一种非常特殊的映射结构。具有三个特性:
①key和value均为String
②属性表可保存至文件,也可从文件读取
③可使用一个二级表作为默认表。
在Java中类Properties实现了抽象类型property map。
property map普遍用于指定程序的配置选项。
java.util.Properties (from Version 1.0)
方法 | 描述 |
---|---|
Properties() | 创建一个空的property map |
Properties(Properties defaults) | 创建一个具有默认值的空的propery map |
String getProperty(String key) | 获取与key相关的属性值,如果该key不在此map中,则继续查找此map的默认表 |
String getProperty(String key,String defaultValue) | 查找过程同上,若最终没查找到此key,返回参数defaultValue |
void load(InputSream in) | 从InputStream中载入属性映射 |
void store(OutputStream out, String commentString) | 向OutputStream中存储属性映射 |