是否有一些Java实用程序,它将扩展〜和env。字符串中的变量?
像“〜/ bin; $ {MY_PATH}”->“ / home / john / bin; / dev / null”
谢谢
基本上,您想使用环境变量进行字符串插值并扩展主目录。我不知道后者的简单方法,但是如果您使用Spring进行设置,则可以使用它的PropertyPlaceholderConfigurer替换字符串中的占位符。
默认情况下,环境变量包含在占位符替换集中。
更新:由于这是来自用户的,因此您仍然可以使用Spring helper类:
String stringToBeInterpolated = ....;
Properties properties = System.getProperties();
PropertyPlaceholderHelper helper = new PropertyPlaceholderHelper("${","}");
String interpolatedValue = helper.replacePlaceholders(stringToBeInterpolated , properties);
这对〜没有帮助,但是到那时,我假设您可以执行一个相当简单的字符串替换操作。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句