我有一个应用程序,其中有一个变量“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/