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 create a ResourceBundle from a file name (not a base name) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to create a ResourceBundle from a file name (not a base name)" Watch "How to create a ResourceBundle from a file name (not a base name)" New topic
Author

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

Martin Wunderlich
Greenhorn

Joined: May 06, 2006
Posts: 9
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
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

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.


Regards, Rene Larsen
Dropbox Invite
Martin Wunderlich
Greenhorn

Joined: May 06, 2006
Posts: 9
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.
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

It takes an InputStream - a FileInputStream is an InputStream
Martin Wunderlich
Greenhorn

Joined: May 06, 2006
Posts: 9
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to create a ResourceBundle from a file name (not a base name)