我不知道发生了什么。
这是我的 Titles_en_US.properties 文件:
WEBSITE.TITLE = Hello World
FOOTER.DISCLAIMER = Disclaimer
FOOTER.TERMS_OF_USE = Terms of Use
FOOTER.PRIVACY_POLICY = Privacy Policy
这是我的方法:
private String getTitle() throws Exception {
System.out.println("\n\n==>"+getProperty("FOOTER.DISCLAIMER",LabelsFile()));
return getProperty("WEBSITE.TITLE", LabelsFile());
}
FOOTER.DISCLAIMER
和 WEBSITE.TITLE
都在同一属性文件中,但其中一个正在工作,另一个抛出以下错误:
==>Disclaimer
Resources.ResourceBundle.java:getProperty()
java.util.MissingResourceException: Can't find resource for bundle java.util.PropertyResourceBundle, key WEBSITE.TITLE
请指出我哪里出错了?
更新
我注意到当我换行时它工作正常。无法理解为什么资源包不从属性文件的第一行读取?
最佳答案
我发现当我在属性文件顶部换行时,它就开始正常工作。然后我搜索了为什么 java ResourceBundle 没有读取属性文件的第一行,并发现了这个 POST 。在这篇文章中说:
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.
并且在上述帖子中还建议将属性文件的编码更改为 ISO-8859-1。
关于java.util.MissingResourceException : Can't find resource for bundle java. util.PropertyResourceBundle,键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41599435/