Java-Process with Specific File

Process with Specific File

ProcessBuilder offers more control over the processes. For example, you can set the current working directory. Here is an example that executes the Windows paint editor. Notice that it specifies the location and specifies the name of the file to edit as an argument.

Program

0

Program Source

import java.io.File;

public class Javaapp {
  
    public static void main(String[] args) {
        
        try {
            ProcessBuilder pro = new ProcessBuilder();
            pro.directory(new File("C:\\java"));
            pro.command("mspaint","AfricanElephant.jpg");
            pro.start();
        }catch(Exception e)
        {
            System.out.println("Error Execuing Program");
        }
    }
}

Leave a Comment