How to load a resource bundle from a file resource in Java?

Posted by user143794 on Stack Overflow See other posts from Stack Overflow or by user143794
Published on 2009-07-23T15:07:19Z Indexed on 2012/05/31 22:40 UTC
Read the original article Hit count: 158

Filed under:
|

I have a file called mybundle.txt in c:/temp -

c:/temp/mybundle.txt

how do I load this file into a java.util.resource bundle? The file is a valid resource bundle.

This does not seem to work:

java.net.URL resourceURL = null;

String path = "c:/temp/mybundle.txt";
java.io.File fl = new java.io.File(path);

try {
   resourceURL = fl.toURI().toURL();
} catch (MalformedURLException e) { 			
}       	

URLClassLoader urlLoader = new URLClassLoader(new java.net.URL[]{resourceURL});
java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle( path , 
                java.util.Locale.getDefault(), urlLoader );

What is the best way to do this?

© Stack Overflow or respective owner

Related posts about java

Related posts about resourcebundle