File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes How to use PropertyResourceBundle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to use PropertyResourceBundle" Watch "How to use PropertyResourceBundle" New topic
Author

How to use PropertyResourceBundle

Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
I am learning Java internationalization, but I haven't been able find out how to use PropertyResourceBundle. The documentation says that:
"ResourceBundle.getBundle automatically looks for the appropriate properties file and creates a PropertyResourceBundle that refers to it"
I imagine the search is in the class path, But what names should I give to the properties files?

Thanks,

Alejandro Barrero


Your help will be greatly appreciated,
Alejandro Barrero
Tim LeMaster
Ranch Hand

Joined: Aug 31, 2006
Posts: 226
The Javadoc for ResourceBundle.getBundle goes into detail on this
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
Thanks Tim. I just dind't read in detail.
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
Well, I am still having problems. I created two properties files:

com/caveman/internationalization/Paperless_en.properties
com/caveman/internationalization/Paperlessen.properties

I can get then with a class's classloader getResourceAsStream, but I am getting the error:

Can't find bundle for base name Paperless, locale en
The documentation says "Otherwise, getBundle attempts to locate a property resource file. It generates a path name from the candidate bundle name by replacing all "." characters with "/" and appending the string ".properties"."

I am at a loss.
Alejandro Barrero
Ranch Hand

Joined: Aug 01, 2005
Posts: 319
It finally worked with
resourceBunble = ResourceBundle.getBundle("com.caveman.internationalization.Paperless", locale, classLoader);
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to use PropertyResourceBundle