java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key

会有一股神秘感。 提交于 2019-12-08 05:17:20

问题


I don't know whats going on.
Here is my Titles_en_US.properties file:

WEBSITE.TITLE       = Hello World       

FOOTER.DISCLAIMER       = Disclaimer
FOOTER.TERMS_OF_USE     = Terms of Use
FOOTER.PRIVACY_POLICY   = Privacy Policy

Here is my method:

private String getTitle() throws Exception {    
    System.out.println("\n\n==>"+getProperty("FOOTER.DISCLAIMER",LabelsFile()));
    return getProperty("WEBSITE.TITLE", LabelsFile());
}   

Both FOOTER.DISCLAIMER and WEBSITE.TITLE in same properties file but one is working and other is throwing following error:

==>Disclaimer
Resources.ResourceBundle.java:getProperty()
java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key WEBSITE.TITLE

Please advise where I am making mistake?

UPDATE
I noticed that when I give line break then its working fine. Not able to understand why resource bundle is not reading from 1st line of property file?


回答1:


I found that when I give a line break at top of my property file then it started work fine. Then I searched why the java ResourceBundle is not reading first line of the property file and found this POST. In this post said that:

The load(Reader) / store(Writer, String) methods load and store properties from and to a character based stream in a simple line-oriented format specified below. The load(InputStream) / store(OutputStream, String) methods work the same way as the load(Reader)/store(Writer, String) pair, except the input/output stream is encoded in ISO 8859-1 character encoding.

and also in the aforementioned post advised to change the encoding of the properties file to ISO-8859-1.



来源:https://stackoverflow.com/questions/41599435/java-util-missingresourceexception-cant-find-resource-for-bundle-java-util-pro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!