我在 gwt 上有一个带有 GUI 的应用程序。使用这个 gui 我想更改(这是子问题:更改 .properties 文件如何更好(我知道如何使用 .properties 从它们读取属性org.apache.commons.configuration
,但不知道如何编辑(作为字符串或如何...))) .properties 文件。例如:我编写了以下 .properties 文件:
################################################################################
# User permissions #
################################################################################
users = admin, root, guest
users.admin.keywords = admin
users.admin.regexps = test-5, test-7
users.root.keywords = root
users.root.regexps = *
users.guest.keywords = guest
users.guest.regexps = *
那么,例如,如何keywords
为管理员添加?
UPD: 这是我要更改配置文件的配置类:
public class Config {
private static final Config ourInstance = new Config();
private static final CompositeConfiguration prop = new CompositeConfiguration();
public static Config getInstance() {
return ourInstance;
}
public Config(){
}
public synchronized void load() {
try {
prop.addConfiguration(new SystemConfiguration());
System.out.println("Loading /rules.properties");
final PropertiesConfiguration p = new PropertiesConfiguration();
p.setPath("/home/mikhail/bzrrep/DLP/DLPServer/src/main/resources/rules.properties");
p.load();
prop.addConfiguration(p);
} catch (ConfigurationException e) {
e.printStackTrace();
}
final int processors = prop.getInt("server.processors", 1);
// If you don't see this line - likely config name is wrong
System.out.println("Using processors:" + processors);
}
public void setKeyword(String customerId, String keyword){
prop.setProperty("users." + customerId + ".keywords", prop.getProperty("users." + customerId + ".keywords") + ", " + keyword);
prop.
}
public void setRegexp(String customerId, String regexp)
{}
}