How do I specify values in a properties file so they can be retrieved using ResourceBundle#getStringArray?

后端 未结 9 1481
失恋的感觉
失恋的感觉 2020-12-03 06:56

I am trying to use ResourceBundle#getStringArray to retrieve a String[] from a properties file. The description of this method in the documentation

9条回答
  •  盖世英雄少女心
    2020-12-03 07:28

    A Properties object can hold Objects, not just Strings. That tends to be forgotten because they're overwhelmingly used to load .properties files, and so often will only contain Strings. The documentation indicates that calling bundle.getStringArray(key) is equivalent to calling (String[]) bundle.getObject(key). That's the problem: the value isn't a String[], it's a String.

    I'd suggest storing it in comma-delimited format and calling split() on the value.

提交回复
热议问题