Spring loads the properties configuration file

Source: Internet
Author: User

Public static void main (string [] ARGs ){
 
String Path = "E:/workspace/bocmarketdata/src/config/periodcode. properties ";
Try {
Map <string, string> periodcodemap = readconfigformap (PATH );
Set <string> set1 = periodcodemap. keyset ();
For (string S: set1 ){
System. Out. println (S + "," + periodcodemap. Get (s ));
}

} Catch (exception e ){
E. printstacktrace ();
}
}

/**
* Read the file and generate Map <string, string>. value is displayed on the left and on the right of the key.
* @ Param path
* @ Return
* @ Throws exception
*/
Public static Map <string, string> readconfigformap (string path) throws exception {
Bufferedreader BF = NULL;
Try {
Inputstream in = new fileinputstream (new file (PATH ));
// Path E:/workspace/edealingv3.0 _ etof/src/CONF/config/institutionl_ip_config.properties
Reader reader = new inputstreamreader (in );

BF = new bufferedreader (Reader );

} Catch (exception e ){
E. getmessage ();
}
 
String ROW = NULL;
Map <string, string> SMAP = new hashmap <string, string> ();
While (null! = (ROW = BF. Readline ())){
If (! Row. Equals ("")){
If (row. startswith ("#")){
Continue;
}
String key = row. substring (0, row. indexof ("= "));
String value = row. substring (row. indexof ("=") + 1, row. Length ());
SMAP. Put (Key, value );
}
}
BF. Close ();
Return SMAP;
}

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.