2014-02-20 23 views

回答

3

这不是一个系统变量而是环境变量。您可以通过使用System.getenv()来访问这些变量。 System.getProperty()用于返回启动程序时设置的任何变量。例如:

# java -Dmyproperty=myvalue MyProgram 
+0

的System.out.println( System.getenv( “区域”));返回null – gstackoverflow

+1

请注意,在java 8中,你应该写'java -Dmyproperty = myvalue -jar myProgram.jar'而不是'java -jar myProgram.jar -Dyproperty = myvalue',或者'myproperty'将为'null' – Searene

0

要列出所有Java System Properties使用,然后检查,如果你有一个area属性:

Properties props = System.getProperties(); 
props.list(System.out); 

看到这个example

1

System#getProperty让你的系统性能。

您可以访问环境变量地图通过System#getenv

System.out.println(System.getenv("area")); 

应该让你的结果。

编辑:

尝试运行下面的代码,如果你需要的变量出现在控制台或行为是其他定义的变量incosistent检查:

public static void main(String[] args) { 
     Set<String> envSet = System.getenv().keySet(); 
     for (String env : envSet) { 
      System.out.println("Env Variable : " + env + " has value : " 
        + System.getenv(env)); 
     } 

    } 
+0

* System.out.println(System.getenv(“area”)); *返回null – gstackoverflow

+0

@gstackoverflow:打开* new *命令提示符并键入'set area',并告诉我们输出。 – Manish

+0

以cmd输出:* area = 1 * – gstackoverflow

相关问题