Package Org. ifocus. crawler. main; import Java. io. bufferedinputstream; import Java. io. fileinputstream; import Java. io. ioexception; import Java. io. inputstream; import Java. util. enumeration; import Java. util. iterator; import Java. util. list; import Java. util. properties; import Org. JDOM. document; import Org. JDOM. element; import Org. JDOM. jdomexception; import Org. JDOM. text; import Org. JDOM. input. saxbuilder; public class readconfiguration {// read xml configuration file public void readxml (string path) throws jdomexception, ioexception {saxbuilder builder = new saxbuilder (false); document = builder. build (PATH); element site = document. getrootelement (); element BD = site. getchild ("BD"); system. out. println (BD. getchildtext ("name"); system. out. println (BD. getchildtext ("pages");} // read. properties configuration file public void readprop (string path) throws ioexception {inputstream in = new bufferedinputstream (New fileinputstream (PATH); properties prop = new properties (); prop. load (in); enumeration <string> en = (enumeration <string>) prop. propertynames (); While (en. hasmoreelements () {system. out. println (prop. get (en. nextelement ();} public static void main (string ARGs []) throws ioexception, jdomexception {readconfiguration rc = new readconfiguration (); // RC. readprop (". /src/baseurl. properties "); RC. readxml (". /src/baseurl. XML ");}}
The content of the other two configuration files
######. Properties # Baidu site. BD. Name = baidusite. BD. Pages = 5sie. BD. url = http://video.baidu.com/music? Order = hot & Pn = 1 # Music Station yyt. Name = yinyuetaiyyt. Pages = 5yyt. url = http://www.yinyuetai.com/mv/all? Page = 1 #####. xml <? XML version = "1.0" encoding = "UTF-8"?> <Site> <BD> <Name> Baidu </Name> <pages> 5 </pages> <! -- <URL> http://video.baidu.com/music? Order = hot & Pn = 1 </URL> --> </BD> <yyt> <Name> music platform </Name> <pages> 5 </pages> <! -- <URL> http://www.yinyuetai.com/mv/all? Page = 1 </URL> --> </yyt> </site>