public class PropertiesFileUpdate extends Object
Note that this utility only works on simple properties files where each name=value pair exists on single lines (i.e. they do not span multiple lines). But it can handle #-prefixed lines (i.e. comments are preserved).
This utility takes care to read and write using the ISO-8859-1 character set since that is what Properties
uses to load and store properties, too.
| Constructor and Description |
|---|
PropertiesFileUpdate(File file)
Constructor given the .properties file.
|
PropertiesFileUpdate(String location)
Constructor given the full path to the .properties file.
|
| Modifier and Type | Method and Description |
|---|---|
Properties |
loadExistingProperties()
Loads and returns the properties that exist currently in the properties file.
|
void |
update(Properties newProps)
Updates the existing properties file with the new properties.
|
boolean |
update(String key,
String value)
Updates the properties file so it will contain the key with the value.
|
public PropertiesFileUpdate(String location)
location - location of the filepublic PropertiesFileUpdate(File file)
the - properties filepublic boolean update(String key, String value) throws IOException
null, an empty
string will be used in the properties file. If the property does not yet exist in the properties file, it will be
appended to the end of the file.key - the property name whose value is to be updatedvalue - the new property valueIOException - if an error occurs reading or writing the properties filepublic void update(Properties newProps) throws IOException
newProps that
already exists in the properties file, the existing property is updated in place. Any new properties found in
newProps that does not yet exist in the properties file will be added. Currently existing properties
in the properties file that are not found in newProps will remain as-is.newProps - properties that are to be added or updated in the fileIOExceptionpublic Properties loadExistingProperties() throws IOException
IOExceptionCopyright © 2008-2014 Red Hat, Inc.. All Rights Reserved.