System.getProperties()与System.getenv()的区别
1、System.getenv():获取的是操作系统的变量如,path,java_home等,在系统环境变量里面进行配置;
2、System.getProperties():获取的JAVA虚拟机的运行时环境变量,是数据java虚拟机自己的,通过-Dxxxx参数进行指定;如java.runtime.name,sun.boot.library.path等;
举例说明:
public static void testEnvironment() {
Map env = System.getenv();
System.out.println(env);
}
public static void testSystemProperties() {
Map properties = System.getProperties();
System.out.println(properties);
}
运行结果:
System.getProperties():
{configsetroot=C:\WINDOWS\ConfigSetRoot, USERDOMAIN_ROAMINGPROFILE=LENOVO-PC, LOCALAPPDATA=C:\Users\xiaozhan\AppData\Local, PROCESSOR_LEVEL=6, FP_NO_HOST_CHECK=NO, USERDOMAIN=LENOVO-PC, FPS_BROWSER_APP_PROFILE_STRING=Internet Explorer, LOGONSERVER=\\MicrosoftAccount, JAVA_HOME=C:\Program Files\Java\jdk1.8.0_65, SESSIONNAME=Console, ALLUSERSPROFILE=C:\ProgramData, PROCESSOR_ARCHITECTURE=AMD64, GRADLE_HOME=D:\code\gradle-2.9, PSModulePath=C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\, SystemDrive=C:, TVT=C:\Program Files (x86)\Lenovo, =C:=C:\, APPDATA=C:\Users\xiaozhan\AppData\Roaming, READYAPPS=C:\ProgramData\Lenovo\ReadyApps, USERNAME=xiaozhan, ProgramFiles(x86)=C:\Program Files (x86), CommonProgramFiles=C:\Program Files\Common Files, Path=C:/Program Files/Java/jre1.8.0_65/bin/server;C:/Program Files/Java/jre1.8.0_65/bin;C:/Program Files/Java/jre1.8.0_65/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\ProgramData\Lenovo\ReadyApps;C:\Program Files (x86)\VisualSVN\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Java\jdk1.8.0_65\bin;D:\code\gradle-2.9\bin;;D:\code\eclipse-jee-mars-1-win32-x86_64\eclipse;, FPS_BROWSER_USER_PROFILE_STRING=Default, PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC, OS=Windows_NT, COMPUTERNAME=LENOVO-PC, PROCESSOR_REVISION=4501, CLASSPATH=.;C:\Program Files\Java\jdk1.8.0_65\lib;, CommonProgramW6432=C:\Program Files\Common Files, ComSpec=C:\WINDOWS\system32\cmd.exe, ProgramData=C:\ProgramData, ProgramW6432=C:\Program Files, HOMEPATH=\Users\xiaozhan, SystemRoot=C:\WINDOWS, TEMP=C:\Users\xiaozhan\AppData\Local\Temp, HOMEDRIVE=C:, PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel, USERPROFILE=C:\Users\xiaozhan, TMP=C:\Users\xiaozhan\AppData\Local\Temp, CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files, ProgramFiles=C:\Program Files, PUBLIC=C:\Users\Public, NUMBER_OF_PROCESSORS=4, windir=C:\WINDOWS, =::=::\}
System.getProperties():
{java.runtime.name=Java(TM) SE Runtime Environment, sun.boot.library.path=C:\Program Files\Java\jre1.8.0_65\bin, java.vm.version=25.65-b01, java.vm.vendor=Oracle Corporation, java.vendor.url= path.separator=;, java.vm.name=Java HotSpot(TM) 64-Bit Server VM, file.encoding.pkg=sun.io, user.country=CN, user.script=, sun.java.launcher=SUN_STANDARD, sun.os.patch.level=, java.vm.specification.name=Java Virtual Machine Specification, user.dir=D:\code\SourceWorkplace\TestProject, java.runtime.version=1.8.0_65-b17, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Program Files\Java\jre1.8.0_65\lib\endorsed, os.arch=amd64, java.io.tmpdir=C:\Users\xiaozhan\AppData\Local\Temp\, line.separator=
, java.vm.specification.vendor=Oracle Corporation, user.variant=, os.name=Windows 10, sun.jnu.encoding=GBK, java.library.path=C:\Program Files\Java\jre1.8.0_65\bin;C:\WINDOWS\Sun\Java\bin;C:\WINDOWS\system32;C:\WINDOWS
阅读(1709) | 评论(0) | 转发(0) |