Attribute File Read Java

Source: Internet
Author: User

Import java. util. resourcebundle;

/**
* Read attribute files
*/
Public class resourceutil {

Private Static resourcebundle prop = NULL;

Static {
Try {
// Attribute file location. Do not add the. properties suffix.
Prop = resourcebundle. getbundle ("config/dbconfig ");
} Catch (exception ex ){
Ex. printstacktrace ();
}
}

/*
* Returns the string value based on the name key value.
*/
Public static string getstringbykey (string key ){
Return prop. getstring (key );
}

/*
* Returns an int value based on the name key value.
*/
Public static int getintbykey (string key ){
Return integer. parseint (prop. getstring (key ));
}

/*
* Return the long value based on the name key value.
*/
Public static long getlongbykey (string key ){
Return long. parselong (prop. getstring (key ));
}

/*
* Return a Boolean Value Based on the name key value.
*/
Public static Boolean getbooleanbykey (string key ){
Return Boolean. parseboolean (prop. getstring (key ));
}

/*
* Returns the string array value based on the name key value and delimiter split.
*/
Public static string [] getstringarraybykey (string key, string split ){
String value = prop. getstring (key );
Return Value. Split (split );
}

/*
* Returns the string array value based on the name key value.
*/
Public static string [] getstringarraybykey (string key ){
Return getstringarraybykey (key ,",");
}

/*
* Returns the int array value based on the name key value and delimiter split.
*/
Public static int [] getintarraybykey (string key, string split ){
String value = prop. getstring (key );
String values [] = value. Split (split );
Int array [] = new int [values. Length];
For (INT I = 0; I <values. length; I ++)
Array [I] = integer. parseint (Values [I]);
Return array;
}

/*
* Returns the int array value based on the name key value.
*/
Public static int [] getintarraybykey (string key ){
Return getintarraybykey (key ,",");
}

Public static void main (string ARGs []) {
System. Out. println (getstringbykey ("datasource. username "));
}
}

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.