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 "));
}
}