Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java path to Program Files folder in windows 64bit

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.

like image 590
DanM Avatar asked Aug 21 '12 14:08

DanM


People also ask

Where are 64-bit programs stored?

On a 64-bit version of Windows, 64-bit programs are stored in the “C:\Program Files” folder and 32-bit programs are stored in the “C:\Program Files (x86)” folder.

Where can I find 64-bit Java?

In the menu, click Settings > Active Profile. Click the Java icon and then the Advanced tab. Select 32-bit Java (default) or 64-bit Java.

Why dont I have a Java folder in my Program Files?

Android Studio and Android do not use a java from Oracle or Sun but use OpenJDK that is an open sourced java instead, so there won't be a java folder under Program Files if you didn't installed java for other uses. Android Studio's java can be found in C:\Program Files\Android\Android Studio\jre.


2 Answers

You should be using

System.getenv("ProgramFiles(X86)")

You can find the full reference on Wikipedia.

like image 152
adarshr Avatar answered Sep 24 '22 15:09

adarshr


This is the correct answer for 32-bit Program Files directory

System.getenv("ProgramFiles(X86)")

However if a programmer is looking for the 64-bit Program Files folder but running a 32-bit JVM, System.getenv("ProgramFiles") will return "\Program Files (x86)\" as a side effect of 32-bit compatibility. In some cases, a programmer will still want the 64-bit ProgramFiles directory. This solution has its flaws, but will usually work...

System.getenv("ProgramFiles").replace(" (x86)", "")

Which is only marginally better then

System.getenv("SystemDrive") + "\Program Files"    

-Tres

like image 21
tresf Avatar answered Sep 26 '22 15:09

tresf