开发者

Java filename expansion library

开发者 https://www.devze.com 2023-02-15 03:11 出处:网络
I\'m looking for a Java library that helps resolve file paths, for example a library that would do something like:

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消