Add properties file read/write in Java

Source: Internet
Author: User
Import  Java. Io. inputstream;  Import  Java. util. properties;  /**  *  @ Author  Guoxiang *  */  Public   Class  Config {  Private   Static Config instance = Null  ; Private Properties Properties = Null  ;  Private  Config () {Init ();}  Public   Static  Config getinstance (){  If (Instance = Null  ) {Instance = New  Config ();}  Return Instance ;}  /**  * Initialize the configuration file  */      Public   Void  Init (){  Try  {Inputstream is = Config. Class . Getresourceasstream ("/config. properties" ); Properties = New  Properties (); properties. Load (is );} Catch  (Exception e ){  Throw   New Runtimeexception ("failed to get properties! " );}}  /**  * Obtain the corresponding value based on the key value *  @ Param  Key *  @ Return       */      Public  String getvalue (string key ){  Return Properties. getproperty (key );}  /**  *  @ Return  The properties  */      Public  Properties getproperties (){  Return  Properties ;}}  Private   Static   Final String config_path = "config. path" ;  Private  Static Properties Config = Null  ;  Static  {  Try  {Config = Com. tianditu. util. config. getinstance (). getproperties ();}  Catch  (Exception e) {e. printstacktrace () ;}} strdirconfig = Config. getproperty (config_path );
Is the website put in the WEB-INF \ classes, not the website put in the bin
# Map urlsearchmap. url
= Http:// ************* Config. Path = D:/ngis_config/

 

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.