既存のプロパティ ファイルに書き込み/追加する 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/
Workspace=D:\RACHEL\SW\Antivirus
追加後:
Url=jdbc:oracle:thin:@//192.168.1.22:1521/
Workspace=D:\\RACHEL\\SW\\Antivirus
これらの余分なバックスラッシュを削除するには?