ProcessBuilder.environment() has the following syntax.
public Map <String , String> environment()
In the following code shows how to use ProcessBuilder.environment() method.
// ww w . j a va2 s .c o m import java.util.Map; public class Main { public static void main(String[] args) { // create a new list of arguments for our process String[] list = {"notepad.exe", "test.txt"}; // create the process builder ProcessBuilder pb = new ProcessBuilder(list); // get the environment of the process Map<String, String> env = pb.environment(); // get the system drive of the environment System.out.println(env); System.out.println(env.get("SystemDrive")); } }
The code above generates the following result.