Get Windows Directory in Java

A single line of code to get Windows (System directory) of your PC folder path in Java.


Get Windows Directory



class GetWindowsDir
{
public static void main(String args[])
{
System.out.println(System.getenv("windir"));
}
}



System.getenv(): Takes a property name and returns its value. env means environment.

windir: Represents the windows (system directory). Ex: C:\Windows (provided if you install your OS in C)

Sample Output



C:\Windows

Also see my other posts on Getting Java Installation Folder in Java and also Get Operating System name in Java

No comments: