I have a Java class to write/append into existing properties file. After appending, it's replacing all single backslash with double backslash and it places single backslash before every semicolon.
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out= response.getWriter();
String systemPath=request.getParameter("SYSTEMPATH");
String deployPath = getServletConfig().getServletContext().getRealPath("/WEB-INF/DB.properties");
InputStream stream = getServletContext().getResourceAsStream("/WEB-INF/DB.properties");
Properties prop = new Properties();
prop.load(stream);
prop.setProperty("Workspace", systemPath);
File file = new File(deployPath);
FileOutputStream fileOut = new FileOutputStream(file);
prop.store(fileOut, "sample properties");
fileOut.close();
}
Before appending:
Url=jdbc:oracle:thin:@//192.168.1.22:1521/
Workspace=D:RACHELSWAntivirus
after appending:
Url=jdbc:oracle:thin:@//192.168.1.22:1521/
Workspace=D:\RACHEL\SW\Antivirus
How to remove these extra backslashes?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…