1

In my Java Application I have a properties Class (shown below). This class refers to application.properties file on the Linux Server.

What is the correct form to enter the file path, do I need Escape Chars?

Current Properties class:

**
 * Properties class used to obtain properties from the
 * application.properties file
 */
public class MyProperties {

    private static Properties props = new Properties();
    static {
        try {
           //path to file on server
            java.io.InputStream in= new FileInputStream("/path/to/file/application.properties");
            props.load(in);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * Returns a given property by its key
     * @param key
     * @return
     */
    public static String getProperty(String key) {

        return props.getProperty(key);
    }

}

Should I be using: //path//to//file//application.properties rather than my current implementation?

java123999
  • 6,974
  • 36
  • 77
  • 121

1 Answers1

-1

If you use single quote, you don't need to escape anything. it will escape everything needs to be escaped in shell mode.

Try to use:

java.io.InputStream in= new FileInputStream('/path/to/file/application.properties');

According to your comment, I add this link referring to properties files:

Reading Java Properties file without escaping values

Maybe it full fit what you need

Community
  • 1
  • 1
FOP
  • 962
  • 1
  • 10
  • 21