Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

using character entities in java properties file

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??

like image 655
sprugman Avatar asked Jun 12 '26 18:06

sprugman


1 Answers

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 "–").

like image 170
erickson Avatar answered Jun 14 '26 08:06

erickson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!