<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml-engine</artifactId>
<version>2.2.2</version>
</dependency>
yaml
name: John Doe
age: 30
email: johndoe@example.com
import org.yaml.snakeyaml.Yaml;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Map;
public class YamlParser {
public static void main(String[] args) {
Yaml yaml = new Yaml();
try {
FileInputStream inputStream = new FileInputStream("data.yaml");
Map<String, Object> data = yaml.load(inputStream);
String name = (String) data.get("name");
int age = (int) data.get("age");
String email = (String) data.get("email");
System.out.println("Name: " + name);
System.out.println("Age: " + age);
System.out.println("Email: " + email);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
Name: John Doe
Age: 30
Email: johndoe@example.com