public static Map<String, String> getEnv() {
Map<String, String> map = new HashMap();
Process p = null;
try {
p = Runtime.getRuntime().exec("cmd /c set");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null) {
String[] str = line.split("=");
map.put(str[0], str[1]);
}
} catch (IOException e) {
e.printStackTrace();
}
return map;
}
public static void main(String[] args) {
Map<String, String> envMap = getEnv();
envMap.forEach((k,v)-> System.out.println("key:"+k+";value:"+v));
}
返回的结果是: