package com.lf.test;
public class DoConfigVO {
private String xdrFolderName;
private String xdrFileName;
private String originalStreamFolderName;
private String originalStreamFileName;
private String threadCount;
public String getXdrFolderName() {
returnxdrFolderName;
}
public void setXdrFolderName(String xdrFolderName) {
this.xdrFolderName = xdrFolderName;
}
public String getXdrFileName() {
returnxdrFileName;
}
public void setXdrFileName(String xdrFileName) {
this.xdrFileName = xdrFileName;
}
public String getOriginalStreamFolderName() {
returnoriginalStreamFolderName;
}
public void setOriginalStreamFolderName(String originalStreamFolderName) {
this.originalStreamFolderName = originalStreamFolderName;
}
public String getOriginalStreamFileName() {
returnoriginalStreamFileName;
}
public void setOriginalStreamFileName(String originalStreamFileName) {
this.originalStreamFileName = originalStreamFileName;
}
public String getThreadCount() {
returnthreadCount;
}
public void setThreadCount(String threadCount) {
this.threadCount = threadCount;
}
@Override
public String toString() {
return"DoConfig [originalStreamFileName=" + originalStreamFileName
+ ",originalStreamFolderName=" + originalStreamFolderName
+ ",threadCount=" + threadCount + ",xdrFileName="
+ xdrFileName + ",xdrFolderName=" + xdrFolderName + "]";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<DOCONFIG>
<VALUE>
<xdrfoldername>Id</xdrfoldername>
<xdrfilename> msisdn_</xdrfilename>
<originalstreamfoldername>originalStream</originalstreamfoldername>
<originalstreamfilename> xdr_</originalstreamfilename>
<threadcount>50</threadcount>
</VALUE>
</DOCONFIG>
package com.lf.test;
import java.io.File;
import java.util.Iterator;
import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
public class DoXMLReaderUtil {
// 配置文件名
private static String filename = System.getProperty("user.dir")+"\\WebRoot\\WEB-INF\\conf\\doConf.xml";
private DoConfigVO getconfig() {
DoConfigVO config = new DoConfigVO();
try {
File f = new File(filename);
if (!f.exists()) {
System.out.println(" Error : Config file doesn't exist!");
System.exit(1);
}
SAXReader reader = new SAXReader();
Document doc;
doc = reader.read(f);
Element root = doc.getRootElement();
Element data;
Iterator<?> itr = root.elementIterator("VALUE");
data = (Element) itr.next();
config.setXdrFolderName(data.elementText("xdrfoldername").trim());
config.setXdrFileName(data.elementText("xdrfilename").trim());
config.setOriginalStreamFolderName(data.elementText("originalstreamfoldername").trim());
config.setOriginalStreamFileName(data.elementText("originalstreamfilename").trim());
config.setThreadCount(data.elementText("threadcount").trim());
} catch (Exception ex) {
System.out.println("Error : " + ex.toString());
}
return config;
}
public static void main(String[] args) {
DoXMLReaderUtil a=new DoXMLReaderUtil();
System.out.println(a.getconfig().toString());
}
}