日期:2014-05-20 浏览次数:20668 次
InputStream is=Propertie.class.getClassLoader().getResourceAsStream("conf/properties.xml");
public static void sread(InputStream is) {
if(is==null){
System.out.println("properties inputStream is null");//测试用
}
prop = new Properties();
SAXReader reader = new SAXReader();
try {
Document doc = reader.read(is);
Element root = doc.getRootElement();
Iterator<?> rIt = root.elementIterator();
while(rIt.hasNext()) {
Element e = (Element) rIt.next();
Iterator<?> everyIt = e.elementIterator();
while(everyIt.hasNext()) {
Element elem = (Element) everyIt.next();
prop.setProperty(elem.getName(),elem.getTextTrim());
}
}
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}