How to reference a system property within a user-defined .properties file?

后端 未结 3 763
别那么骄傲
别那么骄傲 2020-12-19 03:07

I want to define a property for a working directory(say work.dir=/home/username/working-directory), for my production .properties file, without hard-coding the

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-19 03:24

    Get the property from the file, then replace supported macros.

    String propertyValue = System.getProperty("work.dir");
    String userHome = System.getProperty("user.home" );
    String evaluatedPropertyValue = propertyValue.replace("$user.home", userHome );
    

提交回复
热议问题