fatcodeguy
Programmer
Hi,
I have a "config.properties" file that I use to lookup configuration properties for my app.
However, I want to have several pairs with the same key name, so that i could call the getStringArray() function. I'm thinking something like this:
When I try this, I get
Any suggestions? Much appreciated!!
I have a "config.properties" file that I use to lookup configuration properties for my app.
Code:
//CONFIG_PROPERTY_FILE is constant equivalent to "config"
PropertyResourceBundle configVars = (PropertyResourceBundle)PropertyResourceBundle.getBundle(CONFIG_PROPERTY_FILE,Locale.ENGLISH);
//get key values like this
String myKeyValue = configVars.getString("key");
However, I want to have several pairs with the same key name, so that i could call the getStringArray() function. I'm thinking something like this:
Code:
import java.io.*;
import java.lang.*;
import java.util.*;
public class Test{
//main function
public static void main (String args[]) {
PropertyResourceBundle configVars = (PropertyResourceBundle)PropertyResourceBundle.getBundle("config",Locale.ENGLISH);
String[] arr = configVars.getStringArray("key");
for (int ctr=0;ctr<arr.length;ctr++)
{
System.out.println(arr[ctr]);
}
}//end main
}//end class
Code:
#contents of config.properties
key = first value
key = second value
key = third value
When I try this, I get
Code:
Exception in thread "main" java.lang.ClassCastException
at java.util.ResourceBundle.getStringArray(ResourceBundle.java:291)
at Test.main(Test.java:17)
Any suggestions? Much appreciated!!