java.util.Properties 繼承於 Hashtable ,來表示一個持久的屬性集。它使用鍵值結構存儲數據,每個鍵及其
對應值都是一個字符串。該類也被許多Java類使用,比如獲取系統屬性時, System.getProperties 方法就是返回
一個 Properties 對象
============================
常用方法:
public Object setProperty(String key, String value) : 保存一對屬性。
public String getProperty(String key) :使用此屬性列表中指定的鍵搜索屬性值。
public Set<String> stringPropertyNames() :所有鍵的名稱的集合。
======================
常用:
public class ProDemo2 {
public static void main(String[] args) throws FileNotFoundException {
// 創建屬性集對象
Properties pro = new Properties();
// 加載文本中信息到屬性集
pro.load(new FileInputStream("read.txt"));
// 遍歷集合並打印
Set<String> strings = pro.stringPropertyNames();
for (String key : strings ) {
System.out.println(key+" ‐‐ "+pro.getProperty(key));
}
}
}