title: How do I write to a YAML file using SnakeYaml?
body: <p>Consider the following code:    </p>
  
  <pre><code>public static void dumpObjectToYaml(String key, Object O, String path) throws IOException
  {
      Map&lt;String, Object&gt; data = new HashMap&lt;&gt;();
      data.put(key, O);
  
      File F = new File(path);
      F.mkdirs();
      F.createNewFile();
  
      //write data to File
  }
  </code></pre>
  
  <p>This method is aiming to write the given Object O at the given key, into the YAML file at the given path. (if it doesn't exist it is created.) But obviously the main part is still missing.</p>
  
  <p>Now following <a href="https://code.google.com/p/snakeyaml/wiki/Documentation" rel="noreferrer">the documentation of SnakeYaml</a>, to create a YAML I only need to create a map and put in the Objects at the right keys, which I did.</p>
  
  <p>But nowhere (at least I don't see it) is described how to create a yaml file at a certain path!</p>
  
  <p>The only thing I found was: </p>
  
  <p><strong>"The Yaml.dump(Object data) method accepts a Java object and produces a YAML document"</strong> </p>
  
  <pre><code>public void testDump() 
  {
      Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
      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);
  }
  </code></pre>
  
  <p>and</p>
  
  <p><strong>"Yaml.dump(Object data, Writer output) will write the produced YAML document into the specified file/stream."</strong></p>
  
  <pre><code>public void testDumpWriter() 
  {
     Map&lt;String, Object&gt; data = new HashMap&lt;String, Object&gt;();
     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());
  }
  </code></pre>
  
  <p>But still, even though it says exactly that at the second bit of code, it doesn't seem to support the manipulation of a certain file and it's certainly not shown how to do it.</p>
  
  <p>Is it only me or does the documentation feel very cryptic and specified? Half of it is about special applications that I have never even heard about. I feel really dumb just by looking at it and it makes me kind of angry.</p>
  
  <p>Anyhow; I would really appreciate any help that you could give me.</p>