我想从属性文件中我的键中的值中转义<和>。
我试过用反斜杠,但这似乎行不通:
footer.madeby=\<b\>test\</b\>如何在Java属性键中转义特殊字符?
发布于 2013-11-30 21:00:31
你试图逃避的角色中没有一个是特别的。如果省略反斜杠,下面的代码将加载和打印您的属性:
ResourceBundle bundle = ResourceBundle.getBundle("<name of bundle>");
System.out.println(bundle.getString("footer.madeby"));如果不确定哪些字符需要转义,请尝试使用Properties.store方法之一将属性集写入文件。您可以编写一个小沙箱类,它将为您将属性写入文件。无论Java为您提供哪一种逃避方式,都将是正确的:
Properties myProperties = new Properties();
myProperties.put("footer.madeby", "<b>test</b>");
try(Writer writer = new FileWriter("<your properties name>") {
myProperties.store(writer, null);
}https://stackoverflow.com/questions/20305456
复制相似问题