[英]How to read and write data from yaml file at Run time in Java Spring?
I wanted to read and write some content from yaml
file in Spring Boot
application. 我想在Spring Boot
应用程序中从yaml
文件读取和写入一些内容。 Which parser I have to use and How? 我必须使用哪个解析器,以及如何使用? If someone knows any idea, then please elaborate with an example. 如果有人知道任何想法,请举例说明。 thank you. 谢谢。
Check the documentation for examples. 查看文档以获取示例。
You can use SnakeYaml 您可以使用SnakeYaml
Add dep eg snakeyaml 添加部门,例如snakeyaml
The Yaml class is the entry point for the API: Yaml类是API的入口点:
Yaml yaml = new Yaml();
Now we'll parse a YAML document with the Yaml class: 现在,我们将使用Yaml类解析一个YAML文档:
Yaml yaml = new Yaml(); InputStream inputStream = this.getClass() .getClassLoader() .getResourceAsStream("customer.yaml"); Map<String, Object> obj = yaml.load(inputStream); System.out.println(obj);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.