I have read and tried following
- How to remove the backslash in string using regex in Java?
- Java, Removing backslash in string object
- String replace a Backslash
and many blog as well but all are for removing from string not for properties file
I am trying to remove \
from properties file value but no luck
Here is my config.properties
file
query=select * from users
field=id
and my Java code that is A.java
is
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class A {
public static void main(String[] args) throws IOException {
String configPath = "/home/arif/util-test/config.properties";
Properties prop = new Properties();
FileInputStream configFileInputStream = new FileInputStream(configPath);
prop.load(configFileInputStream);
System.out.println("Property file loaded "+ configPath);
configFileInputStream.close();
String query = prop.getProperty("query");
query += " where " + prop.getProperty("field") + " = 1";
//query = query.replaceAll("\\\\", "");
query = query.replace("\\", "");
prop.replace("query", query);
prop.store(new FileOutputStream(configPath), null);
System.out.println("updated query="+ query);
}
}
and updated config.properties
file
#Mon Oct 03 14:34:27 IST 2016
query=select * from users where id \= 1
field=id
while I am expecting following
#Mon Oct 03 14:34:27 IST 2016
query=select * from users where id = 1
field=id
and getting expected output from terminal or cmd, terminal output is
Property file loaded /home/arif/util-test/config.properties
updated query=select * from users where id = 1
your help will be appreciated! thank you