Java reads the XML/. properties configuration file

Source: Internet
Author: User
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>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.