I have added one environment variable manually in windows 7 and i am getting null while I am trying to get it from java program.
我在Windows 7中手动添加了一个环境变量,当我试图从java程序中获取它时,我得到了null。
public static void main(String[] args) {
System.out.println(System.getenv("name"));
}
I am using java 1.7
我正在使用java 1.7
1 个解决方案
#1
to answer your own question try this :
回答你自己的问题试试这个:
System.out.println(System.getenv());
then you should be able to see all the set values in environment.
那么你应该能够看到环境中的所有设定值。
for example if you are trying to get user home, the property you are looking for is :
例如,如果您要将用户置于家中,您要查找的属性是:
System.out.println(System.getenv("HOMEPATH"));
you may want to check the properties as well, it could be the case that you added something to the properties
您可能还想检查属性,可能是您向属性添加了一些内容
System.out.println(System.getProperties());
also this link might be a use for you:
此链接也可能对您有用:
How can I get System variable value in Java?
如何在Java中获取System变量值?
#1
to answer your own question try this :
回答你自己的问题试试这个:
System.out.println(System.getenv());
then you should be able to see all the set values in environment.
那么你应该能够看到环境中的所有设定值。
for example if you are trying to get user home, the property you are looking for is :
例如,如果您要将用户置于家中,您要查找的属性是:
System.out.println(System.getenv("HOMEPATH"));
you may want to check the properties as well, it could be the case that you added something to the properties
您可能还想检查属性,可能是您向属性添加了一些内容
System.out.println(System.getProperties());
also this link might be a use for you:
此链接也可能对您有用:
How can I get System variable value in Java?
如何在Java中获取System变量值?