import org.yaml.snakeyaml.Yaml; import java.io.FileInputStream; import java.io.FileNotFoundException; public class JvyamlExample { public static void main(String[] args) { try { Yaml yaml = new Yaml(); FileInputStream input = new FileInputStream("example.yaml"); Object data = yaml.load(input); MyObject obj = new MyObject(); obj.setName("John"); obj.setAge(25); yaml.dump(obj, new FileWriter("output.yaml")); } catch (FileNotFoundException e) { e.printStackTrace(); } } } class MyObject { private String name; private int age; } yaml allow-aliases: true allow-bean: true allow-jaxb: false default-scalar-style: DOUBLE_QUOTED


上一篇:
下一篇:
切换中文