Java ResourceBundle leading whitespace in values

prongs picture prongs · May 28, 2012 · Viewed 10.8k times · Source

I'm trying out the example given at Oracle's documentations. The java file is here as shown in that page. Now with this java file, I keep a LabelsBundle.properties file in the same directory.

# This is the default LabelsBundle.properties file
s1 = computer
s2 = disk
s3 = monitor
s4 = keyboard

it seems that the trailing whitespace is not ignored while reading the values and the leading whitespaces are ignored.

So if I want leading spaces to be there, what do I do?

In other words, what do I need to do to read the value of s1 as

 computer

instead of

computer

?

Answer

user268396 picture user268396 · May 28, 2012

A Unicode escape sequence \u0020 should do it, because the properties parser should recognise it as an actual value and the Java String should interpret \u0020 as the Unicode code point for space.

Alternatively, IIRC, you can escape the space with a backslash like this \ my value. Works for keys, too.