I'm trying to add some text to a web app via a java .properties file. I want the text to have an en-dash in it. If I add the character entity, thus:
myProp=Foo – Bar
or
myProp=Foo – Bar
I get the code in my output. If I add the literal character to the properties file (and save as UTF-8):
mProp=Foo – Bar
I get the literal character in the output. How do I add the character entity to the output??
The load(InputStream) method of the Properties class always decodes text files as ISO-8859-1. It doesn't "know" what encoding the editor used when it saved the file.
You can create your own Reader with the correct character encoding, and use the load(Reader) method instead.
Or, you can stick with ISO-8859-1 and escape characters from other character sets using Unicode escapes (\uXXXX, for example, "\u8211" instead of "–").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With