属性文件反斜杠和分号 [英] Properties file backslash and semicolon

查看:273
本文介绍了属性文件反斜杠和分号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个java类来编写/追加到现有的属性文件中。在追加后,它用双反斜杠替换所有单反斜杠,并在每个分号前放置单反斜杠。

I have a java class to write/append into existing properties file. After appending, its 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();
}

在追加之前:

Url = jdbc:oracle:thin:@ // 192.168.1.22:1521 /

Url=jdbc:oracle:thin:@//192.168.1.22:1521/

工作区= D:\ RACHEL \添加后SW:\\ Antivirus

Workspace=D:\RACHEL\SW\Antivirus


Url = jdbc \:oracle \:thin \:@ // 192.168.1.22 \:1521 /

Url=jdbc\:oracle\:thin\:@//192.168.1.22\:1521/

工作区= D \:\ \ RACHEL \\SW \\ antintiirus

Workspace=D\:\\RACHEL\\SW\\Antivirus

如何删除这些额外的反斜杠?

How to remove these extra backslashes?

推荐答案

属性文件 应该有额外的反斜杠开头。特别是,如果没有它们,您可能会得到错误的数据,例如:如果你有 d:\ foo \ new 这并不意味着你的期望。

The properties file should have the extra backslashes to start with. In particular, without them you could end up with the wrong data, e.g. if you have d:\foo\new that wouldn't mean what you expect it to.

反斜杠基本上转义属性文件中敏感的字符。冒号是不必要的(因为它们不在钥匙中),但它们也没有任何伤害。文本的反斜杠加倍是完全有益的。

The backslashes escape characters which are sensitive in properties files, basically. The colons are unnecessary (as they're not in the key) but they don't do any harm either. The doubling of backslashes for text is entirely beneficial.

这在属性文档中有记录 - 特别是,看看在 store() 方法。

This is documented in the Properties documentation - in particular, look at the store() method that you're calling.

这篇关于属性文件反斜杠和分号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆