java:properties:avoid-escaping-characters
This is an old revision of the document!
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:
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(); } };
java/properties/avoid-escaping-characters.1597770077.txt.gz · Last modified: 2023/07/04 19:36 (external edit)