I have a properties file called configuration.properties
, within configuration.properties
is the key-value pair:
email.recipients = [email protected], [email protected]
In my Util.java
class I load the configuration.properties
file:
import org.apache.commons.configuration.PropertiesConfiguration;
import org.apache.commons.configuration.ConfigurationException;
PropertiesConfiguration config = new PropertiesConfiguration("configuration.properties");
EMAIL_RECIPIENT_STRING = config.getString("email.recipients");
I expected to have EMAIL_RECIPIENT_STRING
= "[email protected], [email protected]", but I get EMAIL_RECIPIENT_STRING
= "[email protected]" only. What's the reason for this happening?
It appears you're using Apache's PropertiesConfiguration. The docs states
value can contain value delimiters and will then be interpreted as a list of tokens. Default value delimiter is the comma ','.
getString
only returns the first token. You need to use getStringArray
to return all the properties
String recipients = config.getStringArray("email.recipients");
Actually propConfig.setDelimiterParsingDisabled(true) is working, but you must load the config file after this setting, for example:
propConfig = new PropertiesConfiguration();
propConfig.setDelimiterParsingDisabled(true);
propConfig.load(propertiesFile);
if your code like is :
propConfig = new PropertiesConfiguration(propertiesFile);
propConfig.setDelimiterParsingDisabled(true);
then the setting won't work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With