I'm looking for a Java library that helps resolve file paths, for example a library that would do something like:
String abs = Files.expand("$HOME/.bashrc")
or
String abs = Files.expan开发者_Python百科d("~/$OTHER_DIR/../file")
and resolve those to a file path. Does any such thing exist?
Thanks!
Use the getEnv
. Example:
String variable = System.getenv("WINDIR");
System.out.println(variable);
To discover them all, use:
Map<String, String> variables = System.getenv();
for (Map.Entry<String, String> entry : variables.entrySet())
{
String name = entry.getKey();
String value = entry.getValue();
System.out.println(name + "=" + value);
}
Complete article in http://blog.codebeach.com/2008/02/get-environment-variables-in-java.html
That will be a platform dependent solution. (%var% in windows, $var in unix etc). Could you just use system properties?
精彩评论