Java path to Program Files folder in windows 64bit

DanM picture DanM · Aug 21, 2012 · Viewed 8.5k times · Source

i`m trying to get the default Program Files folder on java. When I use:

 System.getenv("ProgramFiles")

It returns "C:\Program Files" instead of "C:\Program Files (x86)"

I can add manually +(x86) but if the user will use 32bit system it will be the wrong folder.

Answer

adarshr picture adarshr · Aug 21, 2012

You should be using

System.getenv("ProgramFiles(X86)")

You can find the full reference on Wikipedia.