Can we read the OS environment variables in Java?

前端 未结 2 1370
夕颜
夕颜 2020-11-28 13:05

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.getP

2条回答
  •  旧时难觅i
    2020-11-28 13:41

    In case anyone is coming here and wondering how to get a specific environment variable without looping through all of your system variables you can use getenv(String name). It returns "the string value of the variable, or null if the variable is not defined in the system environment".

    String myEnv = System.getenv("env_name");
    

提交回复
热议问题