[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

Access to Win32/NT environment variables in Java?

Is there anyway to access the environment variables of Win32/NT?  Specifically, I'd like to access the "windir" variable as a standard location of an .ini file for my application.  I looked at the output of System.getProperties() and I (at least for my installation of jdk) there is no direct mapping of this variable.

Thanks in advance.
0
mwalker
Asked:
mwalker
1 Solution
 
jhanceCommented:
There is no direct way to do this without writing a native method and calling a Windows API.  Here is a more portable way:

You can specify a property to java when you run the interpreter.  If you're running Sun's JDK, you can do it like this:

java -DWINDIR=%WINDIR% myprog.class

Now in your application, you can get the value of WINDIR like:

String windir = System.getProperty("WINDIR");


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now