Skip to content
Advertisement

Properties File multi-line values using PropertiesConfiguration

So far, I have this project where I read in a properties file using PropertiesConfiguration (from Apache), edit the values I would like to edit, and then save change to the file. It keeps the comments and formatting and such, but one thing it does change is taking the multi-line values formatted like this:

JavaScript

and turns it into the array style:

JavaScript

I would like to be able to print those lines formatted as the were before.
I did this via this method:

JavaScript

Advertisement

Answer

I created a work around in case anyone else needs this functionality. Also, there is probably a better way to do this, but this solution currently works for me.

First, set your PropertiesConfiguration delimiter to the new line character like so:

JavaScript

Then you will need to iterate through and update all properties (to set the format):

JavaScript

use this method to format your value list data (as shown above):

JavaScript

Then it is going to be almost correct, except the save function takes the double backslash that is stored in the List, and turns it into 4 back slashes in the file! So you need to replace those with a single backslash. I did this like so:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement