I'm trying to update my database.properties file in my program. However, it seems Java is adding additional character on my properties file.
Here's a snippet of my code.
Properties props = new Properties();
String propsFileName = "src/resources/properties/" + "database.properties";
String[] property = new String[4];
property[0] = "database.properties";
property[1] = url.getText();
property[2] = username.getText();
property[3] = password.getText();
try {
FileInputStream configStream = new FileInputStream(propsFileName);
props.load(configStream);
configStream.close();
props.setProperty("jdbc.driverClassName", Commons.driverClassName);
props.setProperty("jdbc.url", property[1]);
props.setProperty("jdbc.username", property[2]);
props.setProperty("jdbc.password", property[3]);
props.setProperty("jdbc.comment", comments.getText());
FileOutputStream output = new FileOutputStream(propsFileName);
props.store(output, null);
output.close();
} catch (IOException ex) {
ex.printStackTrace();
}
I have this output on my console which is to check if I get the string that I wanted,
Properties = org.postgresql.Driver, jdbc:postgresql://192.168.1.1:1234/db, username, password, null Program Ran on Fri Jun 23 16:00:37 PHT 2017 by user=xngapp234
However, in my database.properties file, I'm getting this output.
jdbc.url=jdbc\:postgresql\://192.168.1.1\:1234/db
jdbc.username=username
jdbc.password=password
jdbc.comment=
jdbc.driverClassName=org.postgresql.Driver
It adds '\' before the ':' which always gives me an error. Any help is appreciated. Thanks!