|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.rhq.core.util.PropertiesFileUpdate
public class PropertiesFileUpdate
This utility helps update one or more properties in a .properties file without losing the ordering of existing properties or comment lines. You can update changes to existing properties or add new properties. Currently, there is no way to remove properties from a properties file (but you can set their values to an empty string).
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 Summary | |
|---|---|
PropertiesFileUpdate(String location)
Constructor given the full path to the .properties file. |
|
| Method Summary | |
|---|---|
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. |
void |
update(String key,
String value)
Updates the properties file so it will contain the key with the value. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public PropertiesFileUpdate(String location)
location - location of the file| Method Detail |
|---|
public void 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 value
IOException
public 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 added or updated in the file
IOException
public Properties loadExistingProperties()
throws IOException
IOException
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||