如:
public class EnvTest {
public static void main(String args[]) {
System.out.println(System.getenv(args[0]));
}
}
运行结果:
C:\java>java EnvTest OS
Windows_NT
又如:
import java.util.Map;
public class EnvDump {
public static void main(String args[]) {
for (Map.Entry entry: System.getenv().entrySet()) {
System.out.println(entry.getKey() + "=" + entry.getValue());
}
}
}
运行结果:
C:\java>java EnvDump
PROCESSOR_ARCHITECTURE=x86
LOGONSERVER=\\ZZ3Z100
HOMEDRIVE=C:
HOMEPATH=\Documents and Settings\Owner.LEGEND-A7R5PDTM
SESSIONNAME=Console
TMP=C:\DOCUME~1\OWNER~1.LEG\LOCALS~1\Temp
java_home=c:\jdk1.5
windir=C:\WINDOWS
ant_home=c:\ant1.6
PROCESSOR_IDENTIFIER=x86 Family 15 Model 2 Stepping 4, GenuineIntel
SystemDrive=C:
USERPROFILE=C:\Documents and Settings\Owner.LEGEND-A7R5PDTM
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH
CommonProgramFiles=C:\Program Files\Common Files
NUMBER_OF_PROCESSORS=1
ComSpec=C:\WINDOWS\system32\cmd.exe
COMPUTERNAME=ZZ3Z100
OS=Windows_NT
USERNAME=Owner
CLIENTNAME=Console
=ExitCode=00000000
TEMP=C:\DOCUME~1\OWNER~1.LEG\LOCALS~1\Temp
USERDOMAIN=ZZ3Z100
ALLUSERSPROFILE=C:\Documents and Settings\All Users.WINDOWS
PROCESSOR_LEVEL=15
SystemRoot=C:\WINDOWS
classpath=c:\jdk1.5\lib;c:\java
=C:=C:\java
APPDATA=C:\Documents and Settings\Owner.LEGEND-A7R5PDTM\Application Data
Path=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;
c:\jdk1.5\bin;c:\ant1.6\bin
PROMPT=$P$G
PROCESSOR_REVISION=0204
ProgramFiles=C:\Program Files
C:\java>