import java.util.*;
public class TestEnv { public static void main(String[] args){
Properties prop = System.getProperties();
Enumeration e = prop.propertyNames();
while(e.hasMoreElements()) {
System.out.println(System.getProperty(e.nextElement().toString()));
} }
}
public class TestEnv { public static void main(String[] args){
Properties prop = System.getProperties();
Enumeration e = prop.propertyNames();
while(e.hasMoreElements()) {
System.out.println(System.getProperty(e.nextElement().toString()));
} }
}
reasons - it was taken out of the API a while ago. If you want to pass
environment information in you'll have to provide -D<variable-name>=<value>
to the java executable, then you can use System.getProperty().javah will generate C stubs for methods ed using the "native" keyword,
for making calls from java to C. You could always build a bridge to a
library and then call getenv() from the standard C libraries.If you're working in Win32 then you could write a COM component which
exposes the information you need and use J-Integra (no I don't work for
them) to get access to it from Java.
高手啊!!:)
如果你只想得到某一个环境变量的话也可以
System.getProperty("os.name");之类的