我有一个 Java 类可以写入/附加到现有的属性文件中。附加后,它将所有单反斜杠替换为双反斜杠,并将单个反斜杠放在每个分号之前。
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();
}
附加前:
url=jdbc:oracle:thin:@//192.168.1.22:1521/
工作区=D:\RACHEL\SW\Antivirus
附加后:
url=jdbc:oracle:thin:@//192.168.1.22:1521/
工作区=D:\\RACHEL\\SW\\防病毒
如何删除这些额外的反斜杠?