Forums Register Login

How to create a ResourceBundle from a file name (not a base name)

+Pie Number of slices to send: Send
Hi there,

I am creating a program to process ResourceBundles and do stuff to the keys and values. However, I have come across the problem that there doesn't seem to be a constructor for the ResourceBundle class that would take a file name as input. The only way I can create ResourceBundles, it seems, is by referring to them with the fully qualified class name (e.g. com.example.MyBundle) as the base name.

Any ideas how I can get a working ResourceBundle object by passing in the file name (e.g. "/Volumes/users/me/myBundle.properties")??

Cheers,

Martin
+Pie Number of slices to send: Send
Why not use the Properties class - and initialize it with a FileInputStream??

BTW - when you use a ResourceBundle, you don't need the .properties extension.
+Pie Number of slices to send: Send
This one here:

http://java.sun.com/j2se/1.4.2/docs/api/java/util/Properties.html

That class doesn't seem to take a FileInputStream. It would work with PropertyResourceBundle, but that class is not meant to be used directly, according to the Java doc. I have tried it, but couldn't get the locale property of the instance after creation.

Cheers,

M.
+Pie Number of slices to send: Send
It takes an InputStream - a FileInputStream is an InputStream
+Pie Number of slices to send: Send
Hi there,

I have been playing around with this a bit more and I am still stuck.
I can create a PropertyResourceBundle using the InputStream of my .properties file, but the getLocale() method on that PropertyResourceBundle still returns null. In a way it makes sense, because the constructor apparently isn't smart enough to take the locale ID from the file of the InputStream (e.g. "myFile_en_US").

So, what can I do to get a usable ResourceBundle object from my physical file?? (as opposed to having it in a Java package with a fully qualified name)

Cheers,

M.
Nothing? Or something? Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1536 times.
Similar Threads
Correct location of language properties bundle files
ResourceBundle
Can't find property file when using ResourceBundle.getBundle
properties file using the ResourceBundle class?
Overriding Message Bundles in JSF 2.x
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 00:58:32.