不经意看到Properties 这个类,一直以为某个jar包里的,没发现是hashtable的子类,于是看了一下读取文件的方法。
读取xml:
Properties pro=new Properties();
pro.loadFromXML(new FileInputStream(new File("D:/projects/test/src/xmlread/root.xml")));
String root=pro.getProperty("root");
System.out.println(root);
pro.load(new FileInputStream(new File("D:/projects/test/src/xmlread/top.properties")));
String username=pro.getProperty("username");
System.out.println(username);
xml的格式必须符合一下格式,不是随便写节点就行的。
xml
test the properties
属性文件:
username=ssg
分享到:
2011-03-09 11:15
浏览 601
评论