Search code examples
javaencodingpropertiesdefaultcp1250

java.util.Properties and Cp1250


Can I use java.util.Properties with encoding different then default?


Solution

  • Not unless you

    1. are running java 6 or later
    2. control the code loading the properties file, and can use a Reader. See the javadoc.

    This is a pretty annoying flaw in the spec. There are several workarounds, probably the simplest being to auto-generate a unicode-escaped compliant .properties file from an encoding-appropriate (cp1250, utf-8, whatever) source.

    Java ships with a transcoder called native2ascii to do this for you:

    There are some aged RFEs on this subject: