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

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

    example:

    mail.ccEmailAddresses=he@anyserver.at, she@anotherserver.at
    

    ..

    myBundle=PropertyResourceBundle.getBundle("mailTemplates/bundle-name", _locale);
    

    ..

    public List getCcEmailAddresses() 
    {
        List ccEmailAddresses=new ArrayList();
        if(this.myBundle.containsKey("mail.ccEmailAddresses"))
        {
            ccEmailAddresses.addAll(Arrays.asList(this.template.getString("mail.ccEmailAddresses").split("\\s*(,|\\s)\\s*")));// 1)Zero or more whitespaces (\\s*) 2) comma, or whitespace (,|\\s) 3) Zero or more whitespaces (\\s*)
        }       
        return ccEmailAddresses;
    }
    

提交回复
热议问题