如何在 Java Spring 运行时从 yaml 文件读取和写入数据?

我想从应用程序中的yaml文件读取和写入一些内容Spring Boot。我必须使用哪个解析器以及如何使用?如果有人知道任何想法,请举例说明。谢谢你。


暮色呼如
浏览 179回答 1
1回答

慕后森

您可以使用 SnakeYaml添加 dep egsnakeyamlYaml 类是 API 的入口点:Yaml yaml = new Yaml();现在我们将使用 Yaml 类解析 YAML 文档:Yaml yaml = new Yaml();InputStream inputStream = this.getClass()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .getClassLoader()&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; .getResourceAsStream("customer.yaml");Map<String, Object> obj = yaml.load(inputStream);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;System.out.println(obj);
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Java