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

后端 未结 9 1447
失恋的感觉
失恋的感觉 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:17

    public String[] getPropertyStringArray(PropertyResourceBundle bundle, String keyPrefix) {
        String[] result;
        Enumeration keys = bundle.getKeys();
        ArrayList temp = new ArrayList();
    
        for (Enumeration e = keys; keys.hasMoreElements();) {
            String key = e.nextElement();
            if (key.startsWith(keyPrefix)) {
                temp.add(key);
            }
        }
        result = new String[temp.size()];
    
        for (int i = 0; i < temp.size(); i++) {
            result[i] = bundle.getString(temp.get(i));
        }
    
        return result;
    }
    

提交回复
热议问题