Consider the following code:
public static void dumpObjectToYaml(String key, Object O, String path) throws IOException { Map<String, Object> data = new HashMap<>(); data.put(key, O); File F = new File(path); F.mkdirs(); F.createNewFile();
This method is designed to write this O to a given key in a YAML file at a given path. (if it does not exist, it is created.) But, obviously, the main part is still missing.
Now, following the SnakeYaml documentation to create YAML, I need to create a map and put the objects in the right keys, which I did.
But nowhere (at least I donβt see it) describes how to create a yaml file in a specific path!
The only thing I found is:
"The Yaml.dump (Object data) method accepts a Java object and creates a YAML document
public void testDump() { Map<String, Object> data = new HashMap<String, Object>(); data.put("name", "Silenthand Olleander"); data.put("race", "Human"); data.put("traits", new String[] { "ONE_HAND", "ONE_EYE" }); Yaml yaml = new Yaml(); String output = yaml.dump(data); System.out.println(output); }
and
"Yaml.dump (object data, Writer output) will write the created YAML document to the specified file / stream."
public void testDumpWriter() { Map<String, Object> data = new HashMap<String, Object>(); data.put("name", "Silenthand Olleander"); data.put("race", "Human"); data.put("traits", new String[] { "ONE_HAND", "ONE_EYE" }); Yaml yaml = new Yaml(); StringWriter writer = new StringWriter(); yaml.dump(data, writer); System.out.println(writer.toString()); }
Nevertheless, although he definitely says that on the second bit of code he does not seem to support manipulating a certain file, and, of course, it is not shown how to do this.
Is this just me or does the documentation look very mysterious and refined? Half of them relate to special applications that I have not even heard of. I feel very stupid just looking at him and it makes me angry.
Anyway; I would really appreciate any help you could give me.