public static synchronized void setPara (String paras) {
SAXBuilder builder = new SAXBuilder();
Document read_doc = null;
File file = null;
try {
String url = UMParas.class.getResource("/").getPath();
file = new File(url + File.separator + "sysconfig.xml");
read_doc = builder.build(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (JDOMException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Element rootElement = read_doc.getRootElement();
List list = rootElement.getChildren("para");
for (Iterator i = list.iterator(); i.hasNext();) {
Element current = (Element) i.next();
List item = current.getChildren("item");
for (Iterator iterator = item.iterator(); iterator.hasNext();) {
Element name = (Element) iterator.next();
if(name.getAttribute("code").getValue().equals("sametimewebpath")){
name.setAttribute("value", paras);
}
}
}
try{
XMLOutputter outputter = new XMLOutputter();
Format fmt = Format.getPrettyFormat();
fmt.setIndent(" ");
outputter.setFormat(fmt);
outputter.output(rootElement.getDocument(), new FileOutputStream(file.getPath())); //虽然能接受Writer和OutputStream2个接口,但用writer会产生中文乱码
}catch(IOException ioe){
ioe.printStackTrace();
}
reloadDom();
}