Java Process Builder IO异常-赢得';t运行程序

Java Process Builder IO异常-赢得';t运行程序,java,process,processbuilder,Java,Process,Processbuilder,这是我的代码,我不确定为什么会出现以下错误: Opening firefox at Sun Oct 28 21:45:27 EDT 2012 java.io.IOException: Cannot run program "firefox.exe": CreateProcess error=2, The system cannot find the file specified public static void open(String app) { try {

这是我的代码,我不确定为什么会出现以下错误:

 Opening firefox at Sun Oct 28 21:45:27 EDT 2012
 java.io.IOException: Cannot run program "firefox.exe": CreateProcess error=2, The system cannot find the file specified

public static void open(String app) {
        try {
            Calendar calendar = Calendar.getInstance();
            Date now = calendar.getTime();
            System.out.println("Opening " + app + " at " + now);
            ProcessBuilder builder = new ProcessBuilder(app+".exe");
            builder.start();
        }
        catch (IOException e) {
            System.out.println(e);
        }
    }

有什么建议吗?

您必须指定Firefox可执行文件的完整路径。

系统找不到指定的文件对您意味着什么?我输入了“Firefox”。我试着从命令提示符下运行firefox,它成功了。为什么不在这里?看起来好像找不到应用程序。如果当前系统路径中不存在应用程序,则需要提供可执行文件的路径。尝试类似于
System.out.println(新文件(app+“.exe”).exists()
并查看文件是否存在于您运行的位置内(或由
app
字符串提供的路径指定),必须有一种比实际指定每个可能的文件路径更简单的方法。。如何有效地执行此操作?不幸的是,ProcessBuilder似乎忽略了系统默认路径。是否可以添加一个参数来避免忽略它们?@phileaton-您没有使用shell。没有“搜索路径”这样的东西。您必须指定要执行文件的位置。