Monday 27 May 2019

Java: Escape equal sign in properties file


Using \=, you can escape the equal sign in properties file.

app.properties
#Application Properties
#Mon May 27 11:43:49 IST 2019
version=1.23
userQuery=where value \= 'wab12'
vendor=ABC Corporation

As you see the property ‘userQuery’, I escaped = symbol using \.


App.java
package com.sample.app;

import java.io.FileInputStream;
import java.io.IOException;
import java.util.Properties;

public class App {

 public static void main(String args[]) throws IOException {
  Properties properties = new Properties();
  FileInputStream fin = new FileInputStream("/Users/krishna/Documents/app.properties");

  properties.load(fin);

  properties.store(System.out, "Application Properties");
 }

}

Output
#Application Properties
#Mon May 27 11:47:49 IST 2019
version=1.23
userQuery=where value \= 'wab12'
vendor=ABC Corporation


You may like

No comments:

Post a Comment