取得所有的环境变量

 public class GetEnvAndProp {
public static void main(String[] args) {
Map<String, String> getenv = System.getenv();
Set<String> keySet = getenv.keySet();
for (String string : keySet) {
System.out.println(string+ "\t"+getenv.get(string));
}
}
}

输出:

USERDOMAIN_ROAMINGPROFILE    DESKTOP-AATAC0K
LOCALAPPDATA    C:\Users\jjcc\AppData\Local
PROCESSOR_LEVEL    6
USERDOMAIN    DESKTOP-AATAC0K
FPS_BROWSER_APP_PROFILE_STRING    Internet Explorer
LOGONSERVER    \\DESKTOP-AATAC0K
SESSIONNAME    Console
ALLUSERSPROFILE    C:\ProgramData
PROCESSOR_ARCHITECTURE    AMD64
PSModulePath    C:\Program Files\WindowsPowerShell\Modules;C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules
SystemDrive    C:
OneDrive    C:\Users\jjcc\OneDrive
=C:    C:\
APPDATA    C:\Users\jjcc\AppData\Roaming
USERNAME    jjcc
ProgramFiles(x86)    C:\Program Files (x86)
VBOX_MSI_INSTALL_PATH    C:\Program Files\Oracle\VirtualBox\
CommonProgramFiles    C:\Program Files\Common Files
Path    C:/Program Files/Java/jre1.8.0_152/bin/server;C:/Program Files/Java/jre1.8.0_152/bin;C:/Program Files/Java/jre1.8.0_152/lib/amd64;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\jjcc\AppData\Local\Microsoft\WindowsApps;;F:\MySoft\eclipse;
FPS_BROWSER_USER_PROFILE_STRING    Default
PATHEXT    .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
OS    Windows_NT
COMPUTERNAME    DESKTOP-AATAC0K
PROCESSOR_REVISION    5e03
CommonProgramW6432    C:\Program Files\Common Files
ComSpec    C:\WINDOWS\system32\cmd.exe
ProgramData    C:\ProgramData
ProgramW6432    C:\Program Files
HOMEPATH    \Users\jjcc
SystemRoot    C:\WINDOWS
TEMP    C:\Users\jjcc\AppData\Local\Temp
HOMEDRIVE    C:
PROCESSOR_IDENTIFIER    Intel64 Family 6 Model 94 Stepping 3, GenuineIntel
USERPROFILE    C:\Users\jjcc
TMP    C:\Users\jjcc\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
=::    ::\

备注:在windows控制台下可以使用 SET 命令查看和修改环境变量

可以参考:https://www.cnblogs.com/saptechnique/archive/2013/02/17/2914222.html

取得所有的系统属性

 public class GetEnvAndProp {
public static void main(String[] args) {
Properties properties = System.getProperties();
properties.list(System.out);
}
}

输出:

-- listing properties --
java.runtime.name=Java(TM) SE Runtime Environment
sun.boot.library.path=C:\Program Files\Java\jdk1.8.0_152\jr...
java.vm.version=25.152-b16
java.vm.vendor=Oracle Corporation
java.vendor.url=http://java.oracle.com/
path.separator=;
java.vm.name=Java HotSpot(TM) 64-Bit Server VM
file.encoding.pkg=sun.io
user.script=
user.country=CN
sun.java.launcher=SUN_STANDARD
sun.os.patch.level=
java.vm.specification.name=Java Virtual Machine Specification
user.dir=F:\MyCache\eclipse\w1\MyTest
java.runtime.version=1.8.0_152-b16
java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment
java.endorsed.dirs=C:\Program Files\Java\jdk1.8.0_152\jr...
os.arch=amd64
java.io.tmpdir=C:\Users\jjcc\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\jdk1.8.0_152\bi...
java.specification.name=Java Platform API Specification
java.class.version=52.0
sun.management.compiler=HotSpot 64-Bit Tiered Compilers
os.version=10.0
user.home=C:\Users\jjcc
user.timezone=
java.awt.printerjob=sun.awt.windows.WPrinterJob
file.encoding=UTF-8
java.specification.version=1.8
user.name=jjcc
java.class.path=C:\Program Files\Java\jdk1.8.0_152\jr...
java.vm.specification.version=1.8
sun.arch.data.model=64
java.home=C:\Program Files\Java\jdk1.8.0_152\jre
sun.java.command=wiki.jjcc.env.GetEnvAndProp
java.specification.vendor=Oracle Corporation
user.language=zh
awt.toolkit=sun.awt.windows.WToolkit
java.vm.info=mixed mode
java.version=1.8.0_152
java.ext.dirs=C:\Program Files\Java\jdk1.8.0_152\jr...
sun.boot.class.path=C:\Program Files\Java\jdk1.8.0_152\jr...
java.vendor=Oracle Corporation
file.separator=\
java.vendor.url.bug=http://bugreport.sun.com/bugreport/
sun.cpu.endian=little
sun.io.unicode.encoding=UnicodeLittle
sun.desktop=windows
sun.cpu.isalist=amd64

05-11 19:47