● Properties 类是 Hashtable 的子类,该对象是用来处理属性文件的。
● 由于属性文件的 key 和 value 都是字符串类型,所以 Properties 里的 key 和 value 都是字符串类型。
● 存取数据的时候,建议使用 setPropert y和 getProperty 方法。
● 示例
package com.github.map.demo9;
import java.util.Enumeration;
import java.util.Properties;
/**
* @author maxiaoke.com
* @version 1.0
*/
public class Test {
public static void main(String[] args) {
Properties properties = new Properties();
properties.setProperty("hello", "你好");
properties.setProperty("world", "世界");
String hello = properties.getProperty("hello");
System.out.println("hello = " + hello);
String world = properties.getProperty("world");
System.out.println("world = " + world);
Enumeration<?> enumeration = properties.propertyNames();
while (enumeration.hasMoreElements()) {
Object key = enumeration.nextElement();
Object value = properties.get(key);
System.out.println("key = " + key + ",value = " + value);
}
for (String name : properties.stringPropertyNames()) {
String property = properties.getProperty(name);
System.out.println("key = " + name + ",value = " + property);
}
}
}