How to get a File java object from its path string with environments vars? For example:
new File("%SYSTEM_ROOT%/file.txt")
or
new File("${SYSTEM_ROOT}/file.txt")
Syntax that allows getting value of environment variable using % sign is a feature of windows shell. In java you should use System.getenv("SYSTEM_ROOT") instead, so your line should look like: new File(System.getenv("SYSTEM_ROOT") + "/file.txt") or even better new File(new File(System.getenv("SYSTEM_ROOT"), "file.txt")
I know this Question is a little bit old, but no Answer yet.
In another Question about environment variables there is a simliar Problem and they have a sample code for regex:
System Variable Regex
This code replaces all system vars that are in the format ${ENV_VAR}.
Hope that helps,
Kalasch
System.getProperty()won't return an environment variable value..getenv()