项目总结69: System.getenv()和System.getProperties()
START
import java.util.Map; import java.util.Properties; import java.util.Set; public class SystemEnvironmentTest { public static void main(String[] args) { //Java提供了System类的静态方法getenv()和getProperty()用于返回系统相关的变量与属性 // getenv方法返回的变量大多于系统相关 Map<String, String> envMap = System.getenv(); Set<String> keySet = envMap.keySet(); for(String key : keySet){ System.out.println("key = " + key + " || value = " + envMap.get(key)); } // getProperty方法返回的变量大多与java程序有关。Properties本质是HashTable Properties properties = System.getProperties(); Set<String> nameSet = properties.stringPropertyNames(); for(String name : nameSet){ System.out.println("name = " + name + " || value = " + properties.getProperty(name)); } } } ---------------------------------------------- 日志输出 name = java.runtime.name || value = Java(TM) SE Runtime Environment name = sun.boot.library.path || value = C:\ThsSoftware\JDK8u144x64_ths\jdk\jre\bin name = java.vm.version || value = 25.144-b01 ....... name = java.vm.specification.vendor || value = Oracle Corporation name = user.variant || value = name = os.name || value = Windows 7 name = sun.jnu.encoding || value = GBK
END