Java reads the classes configuration file in the project.

Source: Internet
Author: User
Public static string getconfigkey (string key) {string fname = "AA. properties "; string keyval =" "; properties props = NULL; string url = stringutils. class. getclassloader (). getresource ("/"). getpath () + fname;/* read the configuration file string filename = "" from the root directory; If (file. separatorchar = '\') filename = "C: \" + fname; else filename = "/" + fname; * // log.info ("configuration file address ----------" + URL); file = new file (URL); If (! File. isfile () {return NULL;} If (file. exists () {fileinputstream FCM = NULL; try {FD = new fileinputstream (File);} catch (filenotfoundexception E2) {log.info (File + "An error occurred while reading the configuration file! "); E2.printstacktrace ();} props = new properties (); try {props. load. close (); keyval = props. getproperty (key); If (keyval = NULL) {log. error ("the configuration file does not contain the key value" + key +! ");} If (keyval! = NULL & keyval. endswith ("\" ") {keyval = keyval. replaceall ("\" "," ") ;}} catch (ioexception e) {e. printstacktrace (); log.info (File + "An error occurred while reading the attribute value in the configuration file! ") ;}} Else {log.info (File +" the configuration file is not found! ");} Return keyval ;}

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.