I have a property file in my project, say config.properties, having a property field project.searchkey
. Can I have the value of this field as project.searchkey = 'one','two'
?
Will it be considering both the values with the '' sign?
I have a property file in my project, say config.properties, having a property field project.searchkey
. Can I have the value of this field as project.searchkey = 'one','two'
?
Will it be considering both the values with the '' sign?
Using java.util.Properties
(see API)
public class Main {
public static void main(String[] args) {
Properties prop = new Properties();
try {
prop.load(Main.class.getClassLoader().getResourceAsStream("config.properties"));
String propertyValue = prop.getProperty("project.searchkey");
System.out.println(propertyValue);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
It prints 'one','two'
, so it reads everything after the =
as a single String
project.searchkey='one','two'
returns 'one','two'
project.searchkey=one,two
returns one,two
project.searchkey=one, 'two'
returns one, 'two'
etc ...
project.searchkey=one, two, \
three, four, \
five
Best not to have keys with commas, and hence not needing single quotes.
After retrieval of the String value for key "project.searchkey"
:
String value = bundle.getProperty("project.searchkey");
// value is "one, two, three, four, five"
String[] searchKeys = value.split(",\\s*"); // Split by comma and any whitespace.
Of course single quotes could be removed for value.