• <bdo id='NhVeq'></bdo><ul id='NhVeq'></ul>

      <i id='NhVeq'><tr id='NhVeq'><dt id='NhVeq'><q id='NhVeq'><span id='NhVeq'><b id='NhVeq'><form id='NhVeq'><ins id='NhVeq'></ins><ul id='NhVeq'></ul><sub id='NhVeq'></sub></form><legend id='NhVeq'></legend><bdo id='NhVeq'><pre id='NhVeq'><center id='NhVeq'></center></pre></bdo></b><th id='NhVeq'></th></span></q></dt></tr></i><div id='NhVeq'><tfoot id='NhVeq'></tfoot><dl id='NhVeq'><fieldset id='NhVeq'></fieldset></dl></div>
    1. <small id='NhVeq'></small><noframes id='NhVeq'>

      <tfoot id='NhVeq'></tfoot>
      1. <legend id='NhVeq'><style id='NhVeq'><dir id='NhVeq'><q id='NhVeq'></q></dir></style></legend>

        我们可以在 Java 中读取操作系统环境变量吗?

        Can we read the OS environment variables in Java?(我们可以在 Java 中读取操作系统环境变量吗?)

        <small id='45Mqv'></small><noframes id='45Mqv'>

        • <bdo id='45Mqv'></bdo><ul id='45Mqv'></ul>

            <tbody id='45Mqv'></tbody>
          • <tfoot id='45Mqv'></tfoot>
            <i id='45Mqv'><tr id='45Mqv'><dt id='45Mqv'><q id='45Mqv'><span id='45Mqv'><b id='45Mqv'><form id='45Mqv'><ins id='45Mqv'></ins><ul id='45Mqv'></ul><sub id='45Mqv'></sub></form><legend id='45Mqv'></legend><bdo id='45Mqv'><pre id='45Mqv'><center id='45Mqv'></center></pre></bdo></b><th id='45Mqv'></th></span></q></dt></tr></i><div id='45Mqv'><tfoot id='45Mqv'></tfoot><dl id='45Mqv'><fieldset id='45Mqv'></fieldset></dl></div>

            1. <legend id='45Mqv'><style id='45Mqv'><dir id='45Mqv'><q id='45Mqv'></q></dir></style></legend>
                  本文介绍了我们可以在 Java 中读取操作系统环境变量吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的操作系统是 windows7.我想在我的 Java 应用程序中读取环境变量.我搜索了谷歌,很多人的答案是使用方法 System.getProperty(String name)System.getenv(String name).但这似乎不起作用.通过该方法,我可以读取在 JVM 中定义的一些变量的值.

                  My OS is windows7. I want to read the environment variables in my Java application. I have searched google and many people's answer is to use the method System.getProperty(String name) or System.getenv(String name). But it doesn't seem to work. Through the method, I can read some variable's value that defined in the JVM.

                  如果我设置了一个名为Config"的环境变量,其值为some config information",如何在Java中获取该值?

                  If I set an environment variable named "Config", with value "some config information", how can I get the value in Java?

                  推荐答案

                  你应该使用 System.getenv(),例如:

                  You should use System.getenv(), for example:

                  import java.util.Map;
                  
                  public class EnvMap {
                      public static void main (String[] args) {
                          Map<String, String> env = System.getenv();
                          for (String envName : env.keySet()) {
                              System.out.format("%s=%s%n",
                                                envName,
                                                env.get(envName));
                          }
                      }
                  }
                  

                  从 IDE 运行时,您可以定义其他环境变量,该变量将传递给您的 Java 应用程序.例如,在 IntelliJ IDEA 中,您可以在 run 的环境变量"字段中添加环境变量配置.

                  When running from an IDE you can define additional environment variable which will be passed to your Java application. For example in IntelliJ IDEA you can add environment variables in the "Environment variables" field of the run configuration.

                  请注意(正如@vikingsteve 的评论中所提到的)JVM 与任何其他 Windows 可执行文件一样,对环境变量的系统级更改仅在重新启动时传播到进程.

                  有关更多信息,请查看 Java 教程的环境变量"部分.

                  System.getProperty(String name) 用于获取 Java 系统属性 不是环境变量.

                  Notice (as mentioned in the comment by @vikingsteve) that the JVM, like any other Windows executable, system-level changes to the environment variables are only propagated to the process when it is restarted.

                  For more information take a look at the "Environment Variables" section of the Java tutorial.

                  System.getProperty(String name) is intended for getting Java system properties which are not environment variables.

                  这篇关于我们可以在 Java 中读取操作系统环境变量吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  How to send data to COM PORT using JAVA?(如何使用 JAVA 向 COM PORT 发送数据?)
                  How to make a report page direction to change to quot;rtlquot;?(如何使报表页面方向更改为“rtl?)
                  Use cyrillic .properties file in eclipse project(在 Eclipse 项目中使用西里尔文 .properties 文件)
                  Is there any way to detect an RTL language in Java?(有没有办法在 Java 中检测 RTL 语言?)
                  How to load resource bundle messages from DB in Java?(如何在 Java 中从 DB 加载资源包消息?)
                  How do I change the default locale settings in Java to make them consistent?(如何更改 Java 中的默认语言环境设置以使其保持一致?)
                        <tbody id='2QYhr'></tbody>
                    1. <tfoot id='2QYhr'></tfoot>

                        <bdo id='2QYhr'></bdo><ul id='2QYhr'></ul>

                        <legend id='2QYhr'><style id='2QYhr'><dir id='2QYhr'><q id='2QYhr'></q></dir></style></legend>
                        <i id='2QYhr'><tr id='2QYhr'><dt id='2QYhr'><q id='2QYhr'><span id='2QYhr'><b id='2QYhr'><form id='2QYhr'><ins id='2QYhr'></ins><ul id='2QYhr'></ul><sub id='2QYhr'></sub></form><legend id='2QYhr'></legend><bdo id='2QYhr'><pre id='2QYhr'><center id='2QYhr'></center></pre></bdo></b><th id='2QYhr'></th></span></q></dt></tr></i><div id='2QYhr'><tfoot id='2QYhr'></tfoot><dl id='2QYhr'><fieldset id='2QYhr'></fieldset></dl></div>
                          1. <small id='2QYhr'></small><noframes id='2QYhr'>