Why does Java ignore the first line of a .properties file?

烈酒焚心 提交于 2019-11-29 04:34:36

Thanks to @KonstantinV.Salikhov and @pms for their help in hunting this down; I decided to post the answer that was discovered to save people hunting through the comments.

The problem was that my file was the wrong encoding, as mentioned here: http://docs.oracle.com/javase/7/docs/api/java/util/Properties.html

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.

(Emphasis mine).

I changed the encoding of the properties file to ISO-8859-1 and everything worked.

Java does not handle the BOM correctly – you can see it in the properties as key. It is possible to save the file UTF-8 but without BOM. In vim for instance

:set nobomb

See vim wiki

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