2

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.

public static void main(String[] args) {

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

}

I am using java 1.7

Sumit Tiwari
  • 51
  • 1
  • 1
  • 5
  • If you aren't sure when the environment variable will be "active", then restart your computer, to make sure that Java won't use the old values. – Tom May 07 '15 at 11:07

1 Answers1

2

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?

Community
  • 1
  • 1
nafas
  • 5,283
  • 3
  • 29
  • 57