Quick Start

Prerequisites

Apron has no runtime dependencies on other libraries.

Apron can be used with Java 8 or higher.

Installation

To use Apron in a maven based project use the following maven coordinates:

1    <dependency>
2      <groupId>de.poiu.apron</groupId>
3      <artifactId>apron</artifactId>
4      <version>2.1.1</version>
5    </dependency>

Otherwise download the jar-file of Apron from the Github Release page and put it into the classpath of your application.

Usage

Create a de.poiu.apron.PropertyFile object from the content of a .properties file.

Reading a .properties file

Apron is fully compatible with the format supported by java.util.Properties, but allows accessing the key value pairs in a more developer-friendly way.

1// Read the file "application.properties" into a PropertyFile
2final PropertyFile propertyFile= PropertyFile.from(
3  new File("application.properties"));
4
5// Read the value of the key "someKey"
6final String someValue= propertyFile.get("someKey");

Writing changes to a .properties file back

Even more important than reading is writing changes back into a .properties file. Other than java.util.Properies Apron does retain

  • the order of all entries

  • all empty lines

  • all comment lines

  • and even the formatting of unchanged entries

1// Set the value of "someKey" to a new value
2propertyFile.set("someKey", "aNewValue");
3
4// Write the PropertyFile back to file by only updating the modified values
5propertyFile.update(new File("application.properties"));