2013-04-27 66 views
1

我有以下代码,必须将新值添加到.properties文件中的现有属性,如果该属性不存在 - 请创建它。为什么代码不会更改.properties文件

public String saveProperties(ArrayList<Property> properties, String customerId){ 
      final String userPropFieldName = "users." + customerId + ".rules"; 
      try{ 
       PropertiesConfiguration props = new PropertiesConfiguration("/home/mikhail/bzrrep/DLP/DLPServer/src/main/resources/rules.properties"); 

       for (Property property: properties){ 
        String fieldName = "rules." + property.getName() + "." + property.getType(); 
        String[] values = (property.getValue()).split("\\,"); 
        for (String word: values){ 
         System.out.print(word + " "); 
        } 

        if (util.exist(fieldName, props)){ 
         props.setProperty(fieldName, values); 
        } else { 
         props.addProperty(fieldName, values); 
        } 

        String[] userProperties = props.getStringArray(userPropFieldName); 
        if (property.getAccepted()){ 
         userProperties = util.addNewValue(userProperties, fieldName); 
        } else { 
         userProperties = util.removeValue(userProperties, fieldName); 
        } 
        props.setProperty(userPropFieldName, userProperties); 
       } 
      }catch (ConfigurationException e){ 
       e.printStackTrace(); 
      } 
     return "Saved"; 
    } 

我与调试器中运行它,所有值正确的,我的意思是,还有属性和数组中的正确的价值观的正确名称,所以,看到它想出的添加或设置新值,但最后我没有看到属性文件中的任何更改。

回答

相关问题