//获取操作系统的环境变量
Map<String,String> envmap = System.getenv();
Iterator<String> it = envmap.keySet().iterator();
while (it.hasNext()){
String key = it.next();
System.out.println(key + "=" + envmap.get(key));
}
//获取java的系统属性,获取:System.getProperty();设置:System.setProperty()
System.out.println("user.home ======"+System.getProperty("user.home"));
System.out.println("java.class.path =========="+System.getProperty("java.class.path"));
//遍历所有的属性
Properties properties = System.getProperties();
Iterator<Object> iter = properties.keySet().iterator();
while (iter.hasNext()){
String key = (String) iter.next();
System.out.println(key + "=" +properties.get(key));
}
运行结果:
image.png
网友评论