Reputation: 119
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?
Upvotes: 2
Views: 21144
Reputation: 119
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.
Upvotes: 2