Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - get "program files" path

Tags:

java

path

windows

How can I get the current computer's "Program Files" path with Java?

like image 766
Stefanos Kargas Avatar asked Jan 31 '11 13:01

Stefanos Kargas


People also ask

Why is there no java folder in 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.

What is a java path?

The PATH is the system variable that your operating system uses to locate needed executables from the command line or Terminal window. The PATH system variable can be set using System Utility in control panel on Windows, or in your shell's startup file on Linux and Solaris.


2 Answers

Simply by calling System.getenv(...)

System.getenv("ProgramFiles"); 

Notice it will only work in Windows environments, of course :-)

like image 115
Riduidel Avatar answered Sep 22 '22 00:09

Riduidel


System.getenv("%programfiles% (x86)");  

for the 32-bit folder on 64-bit PC's.

Also, it works on any language in Windows Vista and newer. Calling either of the posted responses will work on any language installation, in fact.

like image 34
azvampyre Avatar answered Sep 24 '22 00:09

azvampyre