This content has been marked as final. Show 6 replies
Try this in a SomeClass method. Note the initial "/".
URL url1= this.getClass().getResource("/images/duke.gif"); URL url2= this.getClass().getResource("/properties/config.properties"); //or InputStream in1 = this.getClass().getResourceAsStream("/images/duke.gif"); InputStream in2= this.getClass().getResourceAsStream("/properties/config.properties");
Im having problems even loading direcly from the directory..? I have this structure:
src (source dir)
classes (classes dir)
lang/textRb_en_US.properties (the file I want to load)
Then I have this code:
But it gives me a "java.util.MissingResourceException: Can't find bundle for base name /lang/textRb, locale en_US". I start my application from within Eclipse, and I have tried to move "lang/textRb_en_US.properties" into the classes dir, but same error.
Locale currentLocale = new Locale("en", "US"); ResourceBundle textRb = ResourceBundle.getBundle("/lang/textRb", currentLocale);
Im confused as to there Java looks for ressources, and I need this to work no matter where I put my classes/jar. Could you help me out here?
Resource bundles are a little different -- I didn't realize you wanted to load one. Use use dot instead of /:
For details, read the API: readBundle.
ResourceBundle textRb = ResourceBundle.getBundle("lang.textRb", currentLocale);