de.poiu.apron/apronde.poiu.apronhupfdule/apronde.poiu.apron gives you the ability to read and write properties files while preserving comments, whitespace, and order of entries.
java.util.Properties is one of the simpler ways to add configuration to a project. Properties files are just key value pairs separated by an equals sign.
key=value
other=otherValue
But if you want to edit a properties file programmatically while keeping any formatting, ordering, or commenting that a human did manually you will run into trouble.
This is the niche that de.poiu.apron fills. You can have configuration files which are updated by a program and a human interchangeably.
import de.poiu.apron.PropertyFile;
import de.poiu.apron.entry.PropertyEntry;
import java.nio.file.Files;
import java.nio.file.Path;
void main() throws Exception {
var path = Path.of("config.properties");
var fileContents = """
key=value
# Context here
otherKey=otherValue
""";
Files.writeString(path, fileContents);
PropertyFile file = PropertyFile.from(path.toFile());
// value
System.out.println(file.get("key"));
file.appendEntry(new PropertyEntry("port", "4031"));
file.saveTo(path.toFile());
// key=value
// # Context here
// otherKey=otherValue
// port = 4031
System.out.println(Files.readString(path));
}