目的 :
1、读取文件
2、管理键值内容,能够增删改查,遍历
3、能够输出或者写入文件
代码 :
package cn.com.test;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Map.Entry;
import java.util.Properties;
public class TestProperty {
public static void main(String args[]) throws IOException{
String filePath = System.getProperty("user.dir")+"\\src\\pubDbConfig.properties" ;
System.out.println(System.getProperty("file.encoding"));
InputStreamReader fis = new InputStreamReader(new FileInputStream(filePath),"GBK");
Properties pro = new Properties();
pro.load(fis);
pro.list(System.out);
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
System.out.println(pro.getProperty("pub.province_name"));
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
for(Entry<Object,Object> a : pro.entrySet()){
System.out.println(a.getKey()+"=/t"+a.getValue());
}
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
pro.put("new One", "人生的风景");
for(Entry<Object,Object> a : pro.entrySet()){
System.out.println(a.getKey()+"=/t"+a.getValue());
}
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<");
pro.remove("new One");
for(Entry<Object,Object> a : pro.entrySet()){
System.out.println(a.getKey()+"=/t"+a.getValue());
}
}
}
结果不贴 ,不过请注意,插入后的值的位置