How to access Java path programmatically

Create the following java file:

public class Environment {

	public static void main(String[] argv){

		String path = System.getenv("PATH");
		
		System.out.println( "path = " + path ); 
	}
}

The output will be:

path = %USERPROFILE%\AppData\Local\Microsoft\WindowsApps;;C:\Program Files\Docker Toolbox;

The environment variables can be accessed in java using the System object. The getEnv method returns the variables using their names in the environment.

References:

Java 7 System

Share this article:

Recent Comments