2013-04-27 3 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"; 
    } 

내가 디버거를 실행하고 모든 값은 바로, 내 말은, 호텔과 배열의 적절한 값의 적절한 이름이있다, 그래서 값이되었지만 마지막으로 속성 파일에 변경 사항이 표시되지 않았습니다.

답변

1

props.save(); 

더 읽기 파일에 수정 된 속성을 저장 : 직접 소스 코드에 속성을 저장, BTW http://commons.apache.org/proper/commons-configuration/userguide/howto_properties.html#Saving

을 (SRC/메인/자원/rules.properties는)은 일반적으로 나쁜 생각 .

+0

아, 네. 나는 코드를 바라보고 있었고 문제를 찾을 수 없었다. 그리고 내가 아는 소스 코드를 저장하는 것에 대해서. 일시적입니다. –

관련 문제