Java.lang.ProcessBuilder.directory() Method



Description

The java.lang.ProcessBuilder.directory() method returns this process builder's working directory. Subprocesses subsequently started by this object's start() method will use this as their working directory. The returned value may be null − this means to use the working directory of the current Java process, usually the directory named by the system property user.dir, as the working directory of the child process.

Declaration

Following is the declaration for java.lang.ProcessBuilder.directory() method

public File directory()

Parameters

NA

Return Value

This method returns this process builder's working directory

Exception

NA

Example

The following example shows the usage of lang.ProcessBuilder.directory() method.

package com.tutorialspoint;

public class ProcessBuilderDemo {

   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 working directory of the process
      System.out.println("" + pb.directory());
   }
}

Let us compile and run the above program, this will produce the following result −

null
java_lang_processbuilder.htm
Advertisements