title: How do I write a comment to a PropertiesConfiguration file?
body: <p>Given one of these instances: org.apache.commons.configuration.PropertiesConfiguration I want to write a comment.  How?</p>
  
  <pre><code>pc = new PropertiesConfiguration();
  
  writeComment("this is a comment about the stuff below"); // HOW DO I WRITE THIS?
  pc.addProperty("label0", myString);
  writeComment("end of the stuff that needed a comment.");
  </code></pre>
  
  <p><b>Edit: I have a crude solution.  Hopefully it can be improved upon.</b></p>
  
  <hr>
  
  <p>Here's the best I could do.  It leaves an extraneous line in the file.</p>
  
  <pre><code>pc = new PropertiesConfiguration();
  writeComment(pc, "The following needed a comment so this is a comment.");
  pc.addProperty(label0, stuff0);
  writeComment(pc, "End of the stuff that needed a comment.");
  
  ...
   private void writeComment(PropertiesConfiguration pc, String s)
   {
      String propertyName = String.format("%s%d", "comment", this.commentNumber++);
  
      pc.getLayout().setComment(propertyName, s + " (" + propertyName + ")");
  
      // make a dummy property 
      pc.addProperty(propertyName, "."); 
           // put in a dummy right-hand-side value so the = sign is not lonely 
   }
  </code></pre>
  
  <p>One of the problems with this approach is that the PropertiesConfiguration doc is a little vague about the layout.  It does not explicitly say that the comment will appear above the dummy line so there seems to be the risk that PropertiesConfiguration is free to re-arrange the file on subsequent invocations.  I have not even seen an guarantee that property line order is preserved so I cannot guarantee that the comment (and dummy line) will always be above the property that the comment applies to: property <code>label0</code>.  Of course, I'm being a little paranoid here.  However, the doc does say that layouts are not guaranteed to remain unmodified.    <b>Hopefully somebody can come up with something without the dummy line and a Java doc or website guarantee on the position of the comment relative to the property it is meant to comment on.</b>  Edit: You might wonder why I would create a dummy property instead of just attaching the comment to one of the properties that would already be in the file.  The reason is because I want a comment to introduce a block of properties and changes (new ones, or a switch in the order) are possible.  I don't want to create a maintenance problem.  My comment should say "this is the section for data mining results" or "this is the section for the schedule" and I should never have to revisit this.</p>