Hi,
There is dedicated class in java to handle properties: java.util.Properties
Look at
javadoc[
^]for more information.
Here is example of use:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertiesTest {
public static void main(String[] args) {
Properties props = new Properties();
String propsFileName = "./src/myconfig.properties";
try {
FileInputStream configStream = new FileInputStream(propsFileName);
props.load(configStream);
configStream.close();
props.setProperty("connection", "new connection settings go here");
props.setProperty("newProperty", "newValue");
FileOutputStream output = new FileOutputStream(propsFileName);
props.store(output, "This description goes to the header of a file");
output.close();
} catch (IOException ex) {
ex.printStackTrace();
}
}
}