How can I get the current computer's "Program Files" path with Java?
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.
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.
Simply by calling System.getenv(...)
System.getenv("ProgramFiles");
Notice it will only work in Windows environments, of course :-)
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With