Configuration File Reading tool V1.0

Source: Internet
Author: User

This is the config. Properties

#DataBase ConfigKJJF.driverClassName=oracle.jdbc.OracleDriverKJJF.databaseURL=jdbc:oracle:thin:@192.168.31.1:1521:zfpay1KJJF.username=ecfront
Package COM. jadyer. util; import Java. io. ioexception; import Java. util. properties;/*** Configuration File Reading tool * @ author http://blog.csdn/net/jadyer * @ version V1.0 * @ editime Jun 7, 2012 5:30:10 * @ created Jun 7, 2012 5:30:10 pm */public class configutil {private properties config;/*** internal class implementation Singleton * @ see can achieve delayed loading and reduce memory overhead, no multithreading problem * @ see is a Class-level internal class, that is, a static member internal class, the instance of this internal class is not bound to the instance of the external class * @ see and will be loaded only when called, this achieves delayed loading */Private Static class singletonholder {// static initializer. JVM ensures thread security. Private Static configutil instance = new configutil ();} /*** get the Instance Object of configutil * @ see when this method is called for the first time, it reads singletonholder for the first time. instance, causing the singletonholder class to be initialized * @ see, while the singletonholder class will initialize its static domain when it is loaded and initialized, to create a configutil instance * @ see because it is a static domain, it will only be initialized once when the VM loads the class, and the virtual machine to ensure its thread security * @ see the advantage of this mode is that the getinstance () method is not synchronized and only executes access to a domain, therefore, delayed initialization does not increase any access costs * @ author http://blog.csdn/net/jadyer * @ create Jun 7, 2012 7:22:24 */public static configutil getinstance () {return singletonholder. instance;}/*** cloning method * @ see prohibit creating a new object by cloning */@ overridepublic configutil clone () {return getinstance ();} private configutil () {Config = new properties (); try {config. load (configutil. class. getresourceasstream ("/config. properties ");} catch (ioexception e) {system. out. println ("load/config. properties error .... "); E. printstacktrace (); throw new exceptionininitializererror ("failed to load the system configuration file .... ") ;}} Public String getproperty (string key) {return config. getproperty (key);} Public String getproperty (string key, string defaultvalue) {return config. getproperty (Key, defaultvalue);} public int getpropertyforint (string key) {return integer. valueof (config. getproperty (key )). intvalue ();} public int getpropertyforint (string key, string defaultvalue) {return integer. valueof (config. getproperty (Key, defaultvalue )). intvalue ();}}

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.