Java ResourceBundle leading whitespace in values

时光怂恿深爱的人放手 提交于 2019-11-30 00:57:55

问题


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

?


回答1:


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.




回答2:


You can escape space with backlash:

s1 =\ computer


来源:https://stackoverflow.com/questions/10783523/java-resourcebundle-leading-whitespace-in-values

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