Properties
// 使用方法 use method
setProperty(String str_key,String str_value)
// 返回值是一个Set集合
stringPropertyNames():return value is Set Collection
// 将数据存储到硬盘上
store(FileWriter fwobj,String comments)
// 将硬盘上的数据读取到内存中
load(FileReader fr)
public class PropertyDome {
public static void main(String[] args) throws IOException {
// new PropertyDome().method_01();
new PropertyDome().method_02();
}
public void method_01() throws IOException {
Properties pro01 = new Properties();
pro01.setProperty("yuanhao01","18");
pro01.setProperty("yuanhao02","18");
pro01.setProperty("yuanhao03","18");
pro01.setProperty("yuanhao04","18");
pro01.setProperty("yuanhao05","18");
Set<String> key_string = pro01.stringPropertyNames();
// iterator ergodic
Iterator<String> iterator_pro = key_string.iterator();
while (iterator_pro.hasNext()){
String key = iterator_pro.next();
System.out.println("Key is : " + key + "\tValue is : " + pro01.getProperty(key));
}
// for ergodic
for (String key : key_string){
System.out.println("Key is : " + key + "\tValue is : " + pro01.getProperty(key));
}
// store method
FileWriter fileWriter01 = new FileWriter("E:\\folder_io_dome\\a_01.prop");
pro01.store(fileWriter01,"This is property object!! 01");
fileWriter01.close();
}
public void method_02() throws IOException{
Properties pro01 = new Properties();
FileReader fileReader01 = new FileReader("E:\\folder_io_dome\\a_01.prop");
pro01.load(fileReader01);
Set<String> key_string = pro01.stringPropertyNames();
// for ergodic
for (String key : key_string){
System.out.println("Key is : " + key + "\tValue is : " + pro01.getProperty(key));
}
fileReader01.close();
}
}