<dependency> <groupId>org.yaml</groupId> <artifactId>jvyaml</artifactId> <version>1.0.0</version> </dependency> import org.yaml.snakeyaml.Yaml; public class YamlParser { public static void main(String[] args) { Yaml yaml = new Yaml(); try (InputStream inputStream = new FileInputStream("config.yaml")) { Object obj = yaml.load(inputStream); if (obj instanceof Map) { Map<?, ?> map = (Map<?, ?>) obj; // ... } } catch (IOException e) { e.printStackTrace(); } } } import org.yaml.snakeyaml.Yaml; public class YamlGenerator { public static void main(String[] args) { Yaml yaml = new Yaml(); Map<String, Object> data = new HashMap<>(); data.put("name", "John Doe"); data.put("age", 30); data.put("email", "johndoe@example.com"); String yamlString = yaml.dump(data); System.out.println(yamlString); } }


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