[英]Read specific parts of File in java
The syntax of the file type you are trying to read is YAML , so if you need to parse the file and map it to an already defined class, you can use Jackson .
那么映射过程就很简单了:
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
try {
YourCustomClass obj = mapper.readValue(new File("YourFilePath.yaml"), YourCustomClass.class);
System.out.println(obj.getProperty());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
顺便说一句,如果您正在使用 maven,您可以安装 Jackson。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.