How to get an environment variable in Java?

In Java, how to get the value (string) of an environment variable?

asked May 23, 2017 by dtivl (2,500 points)

1 Answer

You may call the System.getenv(name) library function in Java to get the environment variable value.

public static String getenv(String name)

Parameters:
name - the name of the environment variable

Returns:
the string value of the variable, or null if the variable is not defined in the system environment

One example, in the Java REPL:

java> System.getenv("JAVA_HOME")
java.lang.String res0 = "/usr/java/default/"
answered May 27, 2017 by dtivl (2,500 points)

Please log in or register to answer this question.

Related questions

1 answer
1 answer
asked May 23, 2017 by dtivl (2,500 points)
1 answer
asked May 23, 2017 by dtivl (2,500 points)
1 answer
asked May 23, 2017 by dtivl (2,500 points)
1 answer
1 answer
1 answer
Copyright © SysTutorials. User contributions licensed under cc-wiki with attribution required.
Hosted on Dreamhost

...