Initialising ResourceBundles in different dir:

T

t12be

Need help,

Is it possible to initialise a ResourceBundle from another dir?
In the example beneath this file has to be within the same dir of the
source files. I would like to seperate them, how?

ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
Locale("en","US"));

I looked through the API and didn't find anything.
 
G

Guest

Need help,

Is it possible to initialise a ResourceBundle from another dir? In the
example beneath this file has to be within the same dir of the source
files. I would like to seperate them, how?

ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
Locale("en","US"));

I looked through the API and didn't find anything.

You can pass in a ClassLoader to the getBundle() method. This ClassLoader
will determine where ResourceBundle will search for the bundle.
URLClassLoader will best serve your needs.

HTH,
La'ie Techie
 
T

t12be

You can pass in a ClassLoader to the getBundle() method. This ClassLoader
will determine where ResourceBundle will search for the bundle.
URLClassLoader will best serve your needs.
...

First of all thanks of the answer. Only I didn't get out of it. Looked
op how the URLCLassloader works but couldn't get it working. Maybe you
can help me on?

Have the following situation:
+++++++++++++++++++++++++++++
ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
Locale("en","US"));

And the 'langBundle' files are in this dir (relative from src dir)
"../props/"
So I tried the following:
+++++++++++++++++++++++++
URL[] urls = new URL[1];
urls[0] = new URL("../props/");
ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
Locale("en","US"), new URLClassLoader(urls));

Wich didn't work. Has it something to do with the relative url?? Read
something like using relative urls like the need to get a base for the
url by code like this: NameOfClass.class.getResource("")

thx
t12be
 
M

Michael Borgwardt

t12be said:
So I tried the following:
+++++++++++++++++++++++++
URL[] urls = new URL[1];
urls[0] = new URL("../props/");
ResourceBundle lang = ResourceBundle.getBundle("langBundle",new
Locale("en","US"), new URLClassLoader(urls));

Wich didn't work. Has it something to do with the relative url??

What URL? "../props/" is a path, not an URL. You have to prepend it
with "file:", maybe add some slashes.
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top