User Tools

Site Tools


java:properties:avoid-escaping-characters

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Last revisionBoth sides next revision
java:properties:avoid-escaping-characters [2020/08/18 19:51] – created odeftajava:properties:avoid-escaping-characters [2020/08/18 20:01] odefta
Line 1: Line 1:
 ====== Avoid escaping characters in java Properties class ====== ====== Avoid escaping characters in java Properties class ======
 +
 +After calling the **store** method, all the special characters from the key values will be escaped by \ \\
 +Ex: instead of :test= we'll have in the properties file \:test\= \\
 +To avoid this we need to override the store method:
 +
 +<code java>
 +Properties properties = new Properties(){
 + @Override
 + public void store(OutputStream out, String comments) throws IOException {
 + BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(out, System.getProperty("file.encoding")));
 + synchronized (this) {
 + for (Enumeration e = keys(); e.hasMoreElements();) {
 + String key = (String) e.nextElement();
 + String val = (String) get(key);
 + bufferedWriter.write(key + "=" + val);
 + bufferedWriter.newLine();
 + }
 + }
 + bufferedWriter.flush();
 + }
 +};
 +</code>
 +
 +
  
  
  
java/properties/avoid-escaping-characters.txt · Last modified: 2023/07/04 19:36 by 127.0.0.1