首页 > 解决方案 > 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); 
     }

标签: javayaml

解决方案


推荐阅读