在linux命令行上:
public Properties getEnvironment() throws java.io.IOException { Properties env = new Properties(); env.load(Runtime.getRuntime().exec("env").getInputStream()); return env; } Properties env = getEnvironment(); String myEnvVar = env.get("DB_SYSTEM");
答案 0 :(得分:3)
只需使用System.getenv
:
String dbSystem = System.getenv("DB_SYSTEM");
如果不带参数调用它,它将返回所有环境变量:
Map<String, String> env = System.getenv();
String dbSystem = env.get("DB_SYSTEM");