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

后端 未结 9 1850
失恋的感觉
失恋的感觉 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: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);
    

提交回复
热议问题