User Tools

Site Tools


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(){
	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);
java/properties/avoid-escaping-characters.txt · Last modified: 2020/08/18 20:01 by odefta