ResourceBoundle .properties file preffered location

J

jacekfoo

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.
 
M

Moiristo

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.

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.
 
J

jacekfoo

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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,120
Latest member
ShelaWalli
Top