1

In a Java program I have a set of key-value objects and would like to write a String with those properties (that I return as a REST service response). Everything is fine when using java.util.Properties

Properties props = new Properties();
props.put("prop-key", "prop-value");

Writer writer = new StringWriter();
store(writer, "## File comment ##");

This generates the string

## File comment ##

prop-key=prop-value

Now I would like to add comments at each property like this one

## File comment ##

## Property comment
prop-key=prop-value

But using Java's Properties this is not possible. How can I accomplish this task apart from using a StringBuilder or something like that?

Thank you

gvdm
  • 3,006
  • 5
  • 35
  • 73
  • Possible duplicate of [adding comment in .properties files](http://stackoverflow.com/questions/15924220/adding-comment-in-properties-files) – Susannah Potts Aug 09 '16 at 14:45

1 Answers1

2

I've been there before...and I can tell you, the Commons Configuration project from Apache will do the job; it will allow you to write and read Properties files...and for your requirement, have a look at the setComment(String key, String comment) method inside PropertiesConfigurationLayout.

x80486
  • 6,627
  • 5
  • 52
  • 111