Can the key in a Java property include a blank character?

前端 未结 5 1505
陌清茗
陌清茗 2020-12-14 00:09

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 ke

5条回答
  •  太阳男子
    2020-12-14 00:43

    I assume by "properties", you mean a Java property file (as written/read by java.util.Properties).

    Then, as you write yourself,

    foo bar = barefoot
    

    must indeed be interpreted as

    key: foo
    value: bar = barefoot
    

    There's no way to configure this using the built-in Properties class. You must either manipulate your input (escape the whitespace, change it to _ and back...), or write your own parser. Writing your own parser is probably better, as obviously your input isn't really a Java properties file to begin with :-).

提交回复
热议问题