JAVA删除并在YAML文件中写入键和值

时间:2018-12-18 10:37:17

标签: java yaml

1-我想用Java解析yaml文件,但是这种方法每次执行时都会写入密钥,我需要在写入之前将其删除以避免重复输入,请帮忙

我的Yaml file.yaml的内容

dataPrerequis:
codeClient: 12345df
codeClient: 12345d  

方法:

public  static void getTestDumpWriter(String yamlFile,String key1,String 
value1) throws IOException { 
    Map<String, Object> data = new HashMap<String, Object>();
     data.put(key1, value1);
     DumperOptions options = new DumperOptions();
     options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
     options.setSplitLines(`enter code here`false);
     Yaml yaml = new Yaml(options);
     BufferedWriter writer = 
            new BufferedWriter(new FileWriter(yamlFile, true));
     yaml.dump(data, writer); 
     }

0 个答案:

没有答案