在JAVA中,有一个类专门用于处理属性:Properties。Properties类实现了从名字到值得映射。Properties类在java.util ,这个类被用于一集合方式表述系统属性。
E:test.Properties
tom=123
jack=234
ben=345
public void test(){
Properties p = new Properties();
try {
FileInputStream fis = new FileInputStream("E:\\test.properties");
p.load(fis);
String pwd = p.getProperty("tom");
System.out.println(pwd);
Enumeration enu = p.propertyNames();
while(enu.hasMoreElements()){
String key = (String) enu.nextElement();
System.out.println(key+":"+p.getProperty(key));
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}