java - 如何在PropertyFile中指定user.home?

标签 java properties

我有一个应用程序,其中有一个变量“file_Base_Path”,并且我正在从propertyFile(例如sample.properties)读取其值。我想将变量值设置为 user.home 和 ${user.home} 不工作。如何设置 user.home 的值,使其在 Linux 和 Windows 中都可以工作。

注意:我无法使用 System.getProperties('user.home') 因为该值并不总是 user.home 它可能会有所不同

样本.属性:

    file_Base_Path=${user.home}

我如何设置值:

  properties.getProperty("file_Base_Path")  //i'm expecting '/home/user' but it is returning '${user.home}'

谢谢

最佳答案

属性文件不进行环境变量替换...

获取环境变量的方式是

System.getProperties("variablename");

如果“variablename”本身就是变量,为什么不通过属性进行配置?

样本.属性:

userhome.variable.name=user.home

Java代码:

String userhomeVariableName = properties.getProperty("userhome.variable.name");
String userhome = System.getProperties(userhomeVariableName);

关于java - 如何在PropertyFile中指定user.home?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15109084/

相关文章:

python - 定义Python类实例属性

python - @def 与 @property、@foo.setter

Java 在点处分割字符串,除非有特定的内容

java - 我可以从一个 jar/多个模式加载 flyway 迁移吗

java - Apple APNS 和 "Entrust Secure CA root certificate"?

java - 在java中播放Base64编码的音频文件

properties - Gradle 中额外属性的范围?

c# - 构造函数参数的命名约定?

javascript - javascript 中的变量与命名空间

关于 FileOutputStream 的 java OutOfMemoryError?