Christian Koncilia wrote:
Hi Oliver,
thats what I tried before but it doesn't work neither. Another strange thing, if I use
"config.clear()" to clear the whole properties file, everything except(!) the
last thing I read is deleted...
This looks to me like some internal bug. Or do you have another idea?
Bye
Christian
Christian,
I added the following test cases to the unit test class of
PropertiesConfiguration [1]:
public void testClearProperty() throws ConfigurationException
{
if (testSavePropertiesFile.exists())
{
assertTrue(testSavePropertiesFile.delete());
}
assertTrue("Property not found",
conf.containsKey("configuration.loaded"));
conf.clearProperty("configuration.loaded");
conf.save(testSavePropertiesFile);
PropertiesConfiguration conf2 = new
PropertiesConfiguration(testSavePropertiesFile);
assertFalse("Property still contained",
conf2.containsKey("configuration.loaded"));
}
public void testClear() throws ConfigurationException
{
if (testSavePropertiesFile.exists())
{
assertTrue(testSavePropertiesFile.delete());
}
conf.clear();
conf.save(testSavePropertiesFile);
PropertiesConfiguration conf2 = new
PropertiesConfiguration(testSavePropertiesFile);
assertTrue("Configuration not empty", conf2.isEmpty());
}
Here conf is an instance of PropertiesConfiguration that is initialized
with a test properties file. testSavePropertiesFile is a File object,
which points to the target file. Both test cases work for me, so I can't
reproduce your problem.
Which version of Commons Configuration do you use?
After you have removed the property by calling clearProperty() can you
check what containsKey() says? And does the isEmpty() method return true
after you have called clear()?
Oliver
[1]
http://svn.apache.org/repos/asf/jakarta/commons/proper/configuration/trunk/src/test/org/apache/commons/configuration/TestPropertiesConfiguration.java
-----Ursprüngliche Nachricht-----
Von: Oliver Heger [mailto:[EMAIL PROTECTED]
Gesendet: Mo 07.08.2006 21:53
An: Jakarta Commons Users List
Betreff: Re: Commons Configuration: delete entry
Christian Koncilia wrote:
Hello everybody,
I have a question regarding the Commons Configuration. Let's assume I
have a configuration file "myprops.properties" that looks like this:
-------------------------
# written by PropertiesConfiguration
# Mon Aug 07 08:29:12 CEST 2006
group1.entry1 = value1
group1.entry2 = value2
group1.entry3 = value3
-------------------------
Now I would like to simply delete an entry. For instance, I would like
to remove the whole line "group1.entry2 = value2" from my properties
file. How do I do this?
Using
PropertiesConfiguration config =
new PropertiesConfiguration("myprops.properties");
config.clearProperty("group1.entry2 = value2");
config.save();
doesn't work.
Thanks for your help!
Bye
Christian
You only need to pass in the key of the property you want to delete to
clearProperty(), so the line in question should run:
config.clearProperty("group1.entry2");
HTH
Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]