获取所有环境变量的键值
import java.util.Map;
public class TestEnv {
public static void main(String[] args) {
Map<String, String> envMap = System.getenv();
for (String key: envMap.keySet()) {
System.out.printf("%s : %s\n", key, envMap.get(key));
}
}
}
运行结果示例:
PATH : /usr/local/bin:/usr/bin
LESS : -R
LC_CTYPE :
LS_COLORS : di=34;
HOME : /Users/letian
获取特定的环境变量
public class TestEnv {
public static void main(String[] args) {
String value = System.getenv("HOME");
System.out.println(value);
}
}