Tuesday, June 16, 2009

How to Load ResourceBundle

 
Load Resource from different location
// Load resource from specific file object
File f = new File("d:\\\\props\\res.jar");
URL url = f.toURI().toURL();
URL[] urls = new URL[]{url};
ResourceBundle lang = ResourceBundle.getBundle("tw.com.mycomp.res.properties", new Locale("en", "US"), new URLClassLoader(urls));
 
// Load resource from specific URL
URL[] urls = new URL[]{ new URL("file:///d:/props/errmsg.properties") };
ResourceBundle lang = ResourceBundle.getBundle("tw.com.mycomp.res.properties", new Locale("en","US"), new URLClassLoader(urls));