在JavaSpring中,如何在运行时从yaml文件读写数据?
我想从在JavaSpring中,如何在运行时从yaml文件读写数据?,java,spring,spring-mvc,spring-boot,yaml,Java,Spring,Spring Mvc,Spring Boot,Yaml,我想从springboot应用程序中的yaml文件中读写一些内容。我必须使用哪种解析器以及如何使用?如果有人知道任何想法,请举例说明。 谢谢。 查看示例。 查看示例。您可以使用SnakeYaml 添加部门,例如snakeyaml Yaml类是API的入口点: Yaml-Yaml=新的Yaml() 现在,我们将使用YAML类解析YAML文档: Yaml yaml = new Yaml(); InputStream inputStream = this.getClass()
springboot
应用程序中的yaml
文件中读写一些内容。我必须使用哪种解析器以及如何使用?如果有人知道任何想法,请举例说明。
谢谢。
查看示例。
查看示例。您可以使用SnakeYaml
Yaml-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);
Yaml-Yaml=新的Yaml();
InputStream InputStream=this.getClass()
.getClassLoader()
.getResourceAsStream(“customer.yaml”);
映射对象=yaml.load(输入流);
系统输出打印项次(obj);
Yaml-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);
Yaml-Yaml=新的Yaml();
InputStream InputStream=this.getClass()
.getClassLoader()
.getResourceAsStream(“customer.yaml”);
映射对象=yaml.load(输入流);
系统输出打印项次(obj);