Often, you would want a process to be executed in the context of some path, such as listing the files in some directory. In order to do so, we will have to tell ProcessBuilder to launch the process in the context of a given location. We can achieve this by using the directory() method. This method serves two purposes:
- Returns the current directory of execution when we don't pass any parameter.
- Sets the current directory of execution to the passed value when we pass a parameter.
In this recipe, we will see how to execute the tree command to recursively traverse all the directories from the current directory and print it in the form of a tree.