java.util.MissingResourceException: Can't find bundle for base name 'property_file name', locale en_US

后端 未结 9 1844
失恋的感觉
失恋的感觉 2020-12-09 07:30

I am trying to create a utility class ReadPropertyUtil.java for reading data from property file. While my class is located under a util directory , my sky

相关标签:
9条回答
  • 2020-12-09 08:06

    With Eclipse and Windows:

    you have to copy 2 files - xxxPROJECTxxx.properties - log4j.properties here : C:\Eclipse\CONTENER\TOMCAT\apache-tomcat-7\lib

    0 讨论(0)
  • 2020-12-09 08:07

    ResourceBundle doesn't load files? You need to get the files into a resource first. How about just loading into a FileInputStream then a PropertyResourceBundle

       FileInputStream fis = new FileInputStream("skyscrapper.properties");
       resourceBundle = new PropertyResourceBundle(fis);
    

    Or if you need the locale specific code, something like this should work

    File file = new File("skyscrapper.properties");
    URL[] urls = {file.toURI().toURL()};
    ClassLoader loader = new URLClassLoader(urls);
    ResourceBundle rb = ResourceBundle.getBundle("skyscrapper", Locale.getDefault(), loader);
    
    0 讨论(0)
  • 2020-12-09 08:07

    Use the Resource like

    ResourceBundle rb = ResourceBundle.getBundle("com//sudeep//internationalization//MyApp",locale);
    or
    ResourceBundle rb = ResourceBundle.getBundle("com.sudeep.internationalization.MyApp",locale);
    

    Just give the qualified path .. Its working for me!!!

    0 讨论(0)
  • 2020-12-09 08:12

    I have just realized that my error was caused in the naming convention of my property file. When i used xxxx.xxxx.properties i got the error:

    java.util.MissingResourceException: Can't find bundle for base name 'property_file name', locale en_US

    Changing it to something like xxx-xxxx.properties works like a charm. Hope i help someone!

    0 讨论(0)
  • 2020-12-09 08:17

    just right click on the project file in eclipse and in build path select "Use as source folder"...It worked for me

    0 讨论(0)
  • 2020-12-09 08:19

    You should set property file name without .properties extension, it works correctly for me:)

    0 讨论(0)
提交回复
热议问题