Tuesday, June 26, 2012

System Variables and User Defined Variables

Windows Server System Environment Variables and User Variables.

Last week I developed an applet program for an xml masking process in Java.. I was referring to an environment variable in my program. When it was tested by clients they reported an IO Exception for which I couldn't find a cause.. Luckily getMessage() function was handy and I had learned that you can set Environment Variables @ User level and @ System Level.. I have set-up that environment variable @ user level and the program had run successfully, when the client tested the variable was not defined and the program failed..

Code snippet to read OS environment variables

Map<String, String> variables = System.getenv();

for (Map.Entry<String, String> entry : variables.entrySet())
{
   String name = entry.getKey();
   String value = entry.getValue();
   System.out.println(name + "=" + value);
}

No comments:

Post a Comment