-
-
Save bmcculley/565003ed5d8fea5fbd7f605566414bae to your computer and use it in GitHub Desktop.
Simple SnakeYAML example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
master_key_one: | |
sub_key_one : 'value_one' | |
sub_key_two : 'value_two' | |
master_key_two: | |
sub_key_one : 'value_one' | |
sub_key_two : 'value_two' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.yaml.snakeyaml.Yaml; | |
import java.io.FileNotFoundException; | |
import java.io.FileInputStream; | |
import java.io.File; | |
import java.util.Map; | |
public class HelloYaml { | |
@SuppressWarnings("unchecked") | |
public static void main(String[] args) throws FileNotFoundException { | |
Yaml yaml = new Yaml(); | |
System.out.println(yaml.dump(yaml.load(new FileInputStream(new File( | |
"hello_world.yaml"))))); | |
Map<String, Map<String, String>> values = (Map<String, Map<String, String>>) yaml | |
.load(new FileInputStream(new File("hello_world.yaml"))); | |
for (String key : values.keySet()) { | |
Map<String, String> subValues = values.get(key); | |
System.out.println(key); | |
for (String subValueKey : subValues.keySet()) { | |
System.out.println(String.format("\t%s = %s", | |
subValueKey, subValues.get(subValueKey))); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment