Java属性中的键可以包含空白字符吗? [英] Can the key in a Java property include a blank character?
问题描述
我们从数据库中获取属性(我们无法影响),并希望通过键/值映射来访问它们。
我们面临的问题是其中一个属性键包含空白字符。
We are getting properties (that we can not influence) out of a database and want to access them by a key/value mapping. We are facing the problem that one of the property keys includes a blank character.
foo bar = barefoot
这是 - 正确 - 解释如下
This is - correctly - interpreted as follows
key: foo
value: bar = barefoot
有没有办法在键中包含空格,以便它不被解释为分隔符?我猜这种行为就像预期的那样,但我想我可以尝试一下。
Is there a way to include the blank in the key so that it's not interpreted as the delimiter? I guess this behaviour is just like intended, but I thought I could give it a try here.
推荐答案
因为它似乎是分隔符应该 =
,而不是空格。
因此 - keyValuePair.split(=)
应该这样做。
As it seems the delimiter should be =
, not space.
Hence - keyValuePair.split("=")
should do.
如果你正在加载这个从java .properties
文件中,您可以扩展 java.util.Properties
并覆盖此方法
If you are loading this from a java .properties
file, then you can extend java.util.Properties
and override this method
public synchronized void load(InputStream inStream) throws IOException
以便正确解析属性。
这篇关于Java属性中的键可以包含空白字符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!