I have a config.properties files with names like this: names=john,jane
Then I have a class that access that file and loads the names. And I have another class that get a name from somewhere and if that name is in the config.properties prints "SUCCESS"
. The problem is that if I add names to the config.properties, I have to run again the program, it doesn´t load dynamically. What is the alternative to this?
public class PropertiesFile {
private static final char OPENFILES_CONFIG_DELIMITER = ',';
private static final String OPENFILES_CONFIG = "config.properties";
private static org.apache.commons.configuration2.Configuration config;
static {
try {
Parameters params = new Parameters();
FileBasedConfigurationBuilder<FileBasedConfiguration> builder = new FileBasedConfigurationBuilder<FileBasedConfiguration>(PropertiesConfiguration.class)
.configure(params.properties()
.setFileName(OPENFILES_CONFIG)
.setListDelimiterHandler(new DefaultListDelimiterHandler(OPENFILES_CONFIG_DELIMITER)));
config = builder.getConfiguration(); }
catch (ConfigurationException cE) {
//...
}
}
public static Set<String> load() {
String[] thingsToExecute = config.getStringArray("names");
return new HashSet<String>(Arrays.asList(thingsToExecute));
}
}
public class OpenFiles {
private static Set<String> toExecute;
public static void main(String[] args) {
updateToExecute();
connect();
}
private static void connect() {
//code that obatins JSONObject
if (obj4.has("name")) {
String personName = obj4.get("name").toString();
updateToExecute();
if (toExecute.contains(personName)) {
System.out.println("SUCCESS");
} else {
System.out.println(personName+"is not in the list");
}
}
}
private static void updateToExecute() {
toExecute = PropertiesFile.load();
}
}