Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

ResourceBoundle .properties file preffered location

Thread view: 
jacekfoo@gmail.com - 17 Aug 2006 13:54 GMT
Could you tell me where .properties file should be put in my program?
It is put in the same folder as class calling getResourceBoundle and it
still can't find these files.
Or maybe I misunderstood Java tutorial?
I want to use simple class called DefaultBooleanField that is supposed
to return true and false in many languages. In the same folder that
this class resides I have put BooleanField.properties, and
BooleanField_pl.properties.
Function that is supposed to take user readable values looks like that:
       //StaticContent is some static class with some shared data.
    @Override
    public String takeUserText() {
        if(contents)
            return ResourceBundle.getBundle("BooleanField",
StaticContent.getLocale())
                .getString("true");
        return ResourceBundle.getBundle("BooleanField",
StaticContent.getLocale())
            .getString("false");
    }

And Main functions of test program looks like that:
    public static void main(String[] args) {
        StaticContent.setLocale(new Locale("pl", "PL"));
        System.out.println(new DefaultBooleanField(true).takeUserText());
        System.out.println(new DefaultBooleanField(false).takeUserText());
    }

Thanks for any help.
Moiristo - 17 Aug 2006 16:18 GMT
> Could you tell me where .properties file should be put in my program?
> It is put in the same folder as class calling getResourceBoundle and it
[quoted text clipped - 4 lines]
> this class resides I have put BooleanField.properties, and
> BooleanField_pl.properties.

AFAIK, say your root classpath is ./ , then you just have to do
'ResourceBundle.getBundle("BooleanField")'. When it is in a directory,
say ./resources, then you should do
'ResourceBundle.getBundle("resources.BooleanField")'. It retrieves the
location using the ClassLoader.findResource() method, so you could even
override that function and return whatever you like.
jacekfoo@gmail.com - 17 Aug 2006 19:49 GMT
> > Could you tell me where .properties file should be put in my program?
> > It is put in the same folder as class calling getResourceBoundle and it
> > still can't find these files.

> AFIK, say your root classpath is ./ , then you just have to do
> 'ResourceBundle.getBundle("BooleanField")'. When it is in a directory,
> say ./resources, then you should do
> 'ResourceBundle.getBundle("resources.BooleanField")'.

Thanks you were right!
John - 24 Aug 2006 20:25 GMT
> Could you tell me where .properties file should be put in my program?

See the following:
http://weblogs.java.net/blog/joconner/archive/2004/04/i18n_howto_reso.html
http://java.sun.com/developer/technicalArticles/Intl/ResourceBundles/

--
John O'Conner


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.