取得环境变量

来源:互联网 发布:魔兽世界官方数据库7.0 编辑:程序博客网 时间:2024/04/30 06:24

方法1:

byte[] env = new byte[1000];
try{
      Process ObjPrcess = ObjRunTime.exec("cmd /c echo %java_home%");
      InputStream in = ObjPrcess.getInputStream();
      in.read(env);
      String ls_env = new String(env).trim();
      System.out.println("ls_env:"+ls_env);
   }catch(Exception e){e.printStackTrace();}

方法2:

public class GetSysProperties{
    public static void main(String[] argv) {
      System.getProperties().list(System.out);
    }
}