w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Evaluating property value from properties file java

Java doesn't do this replacement automatically, they are just treated as strings. You will have to do the variable replace by System.getenv().

Before that you will have to recognise and take the variable out using regex or some other mechanism.

Pattern p = Pattern.compile("\$\{([0-9a-zA-Z.@]+)}");  
Matcher m = p.matcher(label);

     String var = m.group();
     String envVar = var.replace("${","").replace("}","");
     label = label.replace(var,System.getenv(envVar));

Please note that above code assumes you have only one variable in a line other wise you will have to use a while loop instead of if. Also note that above code may not be syntactically right as I don't have any java IDE with me.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.