Properties files are a popular mean of configuring applications. Of course Commons Configuration supports this format and enhances significantly the basic java.util.Properties class. This section introduces the features of the PropertiesConfiguration class. Note that PropertiesConfiguration is a very typical example for an implementation of the Configuration interface and many of the features described in this section (e.g. list handling or interpolation) are supported by other configuration classes as well. This is because most configuration implementations that ship with Commons Configuration are derived from the common base class AbstractConfiguration, which implements these features.
Below is a simple code which will help you update config.properties File in java.
You need these 3 .jar files in your class path: commons-configuration-1.9.jar, commons-lang-2.6.jar, commons-logging-1.1.2.jar.
package com.crunchify.tutorials; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.PropertiesConfiguration; /** * @author Crunchify.com * */ public class CrunchifyUpdateConfig { public static void main(String[] args) throws ConfigurationException { PropertiesConfiguration config = new PropertiesConfiguration("/Users/<username>/Documents/eclipsewp/CrunchifyTutorials/resources/config.properties"); config.setProperty("company1", "Chase"); config.setProperty("company2", "Paypal"); config.save(); System.out.println("Config Property Successfully Updated.."); } }
Other must read: http://crunchify.com/java-properties-file-how-to-read-config-properties-values-in-java/
Output:
#Crunchify Properties user=Crunchify company1=Chase company2=Paypal company3=Yahoo
The post Java Properties Files: How to Update config.properties File in Java? appeared first on Crunchify.