Looping through .properties files.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Harsha_K
Posted On:   Wednesday, September 1, 2004 07:45 AM

Hi all, I am new to java and also to the Forum. I have a problem while looping. We have a method like: public static final String getComment( String key, Locale locale, String[] resource) { String s=""; try { setBundle(locale,resource[0]); s = comments.getString(key); return s; } catch (MissingResourceException e) { try { setBundle(locale,resource[1]); s = comments.getString(key); return s; } catch (MissingResourceException e1) { try { setBundle(locale,resource[2]); s = comments.getString(key); return s; }catch (MissingResourceException e2) { return "";    More>>
			
Hi all,

I am new to java and also to the Forum.

I have a problem while looping.

We have a method like:
public static final String getComment( String key, Locale locale, String[] resource) {
String s="";
try {
setBundle(locale,resource[0]);
s = comments.getString(key);
return s;
} catch (MissingResourceException e) {
try {
setBundle(locale,resource[1]);
s = comments.getString(key);
return s;
} catch (MissingResourceException e1) {
try {
setBundle(locale,resource[2]);
s = comments.getString(key);
return s;
}catch (MissingResourceException e2) {
return "";
}
}
}


This piece of code is coded to read the String[] resources.

As there are only 3 resources, this one is fine, but I want to have a loop to the length of resources

I want to have the above code using a for loop. I have tried in several ways but the output using th for loop was not as the output as earlier.

could any body help me in here.

Your help is certainly appreciated.
   <<Less

Re: Looping through .properties files.

Posted By:   Pavan_Gattu  
Posted On:   Friday, September 3, 2004 02:04 AM

From your code I understand that "comments" is a ResourceBundle. You can get the enumeration of the keys and iterate through the enumeration to get the values and populate as you like.



Enumeration keys = comments.getKeys();
while (keys.hasMoreElements())
{
String key = (String) keys.nextElement();
String value = comments.getString(key);
/**
Do any other thing withe this key, value pairs
*/
}



Hope this helps.
About | Sitemap | Contact