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()));    
        }   }
}

解决方案 »

  1.   

    You can't get to the environment variables with pure Java for security
    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.
      

  2.   

    to feiyuegaoshan:
    高手啊!!:)
      

  3.   

    同意 scbb(星际Baby) 
    如果你只想得到某一个环境变量的话也可以
    System.getProperty("os.name");之类的