posts - 0,  comments - 5,  trackbacks - 0

          需要用到commons-logging-1.0.4.jar,dom4j-1.4.jar包

          ?1 import?java.io.File;
          ?2 import?java.io.IOException;
          ?3
          ?4 import?org.apache.commons.logging.Log;
          ?5 import?org.apache.commons.logging.LogFactory;
          ?6 import?org.dom4j.Document;
          ?7 import?org.dom4j.io.SAXReader;
          ?8
          ?9 /**
          10 ?*?@author?wufalong
          11 ?*
          12 ?*?TODO?To?change?the?template?for?this?generated?type?comment?go?to
          13 ?*?Window?-?Preferences?-?Java?-?Code?Style?-?Code?Templates
          14 ?*/
          15 public?class?LoadRootElementByConfigFile?{
          16 ????private?static?Log?log?=?LogFactory.getLog(LoadRootElementByConfigFile.class);
          17 ????public?static?Document?getRootElement(){
          18 ????????String?path="";
          19 ????????File?file?=?new?File(".");
          20 ????????try
          21 ????????{
          22 ????????????path?=?file.getCanonicalPath();
          23 ????????}
          24 ????????catch?(IOException?e)
          25 ????????{
          26 ????????????e.printStackTrace();
          27 ????????}
          28
          29 ????????Document?document?=?null;
          30 ????????String?filePath?=?"";
          31 ????????try{?
          32 ????????????filePath?=?path+"/config.xml";
          33 ????????????File?f?=?new?File(filePath);??//服務器運行目錄
          34 ????????????SAXReader?reader?=?new?SAXReader();
          35 ????????????document?=?reader.read(f);
          36 ????????}catch(Exception?e){?
          37 ????????????filePath?=?path+"/src/config.xml";
          38 ????????????File?f?=?new?File(filePath);?//eclipse調試目錄
          39 ????????????SAXReader?reader?=?new?SAXReader();
          40 ????????????try{
          41 ????????????????document?=?reader.read(f);
          42 ????????????}catch(Exception?ex){
          43 ????????????????
          44 ????????????}
          45 ????????}
          46 ????????log.info("配置文件路徑:"+filePath);
          47 ????????return?document;????
          48 ????}
          49 }
          posted on 2007-09-03 10:59 crazy 閱讀(256) 評論(0)  編輯  收藏 所屬分類: java
          主站蜘蛛池模板: 青田县| 眉山市| 玉田县| 应城市| 宁城县| 凤山县| 永新县| 舟曲县| 太仓市| 仁怀市| 延安市| 中山市| 南木林县| 东辽县| 隆昌县| 陇川县| 北辰区| 抚宁县| 吉林市| 双城市| 阿城市| 四平市| 哈密市| 班戈县| 铜鼓县| 普陀区| 保定市| 韩城市| 新邵县| 宣化县| 苍溪县| 曲沃县| 日土县| 浦江县| 景泰县| 蛟河市| 桂东县| 龙陵县| 彝良县| 保定市| 绍兴市|