exec(cmds,null,file);exec的第三个参数file指的是路径
不是文件
设置成null就可以了,就表示使用当前工作路径

解决方案 »

  1.   

    public Process exec(String command, String[] envp, File dir)
              throws IOException
        Executes the specified string command in a separate process with the specified environment and working directory. 
    This method breaks the command string into tokens and creates a new array cmdarray containing the tokens in the order that they were produced by the string tokenizer; it then performs the call exec(cmdarray, envp). The token parsing is done by a StringTokenizer created by the call:  new StringTokenizer(command)
     with no further modification of the character categories. 
    The environment variable settings are specified by envp. If envp is null, the subprocess inherits the environment settings of the current process. The working directory of the new subprocess is specified by dir. If dir is null, the subprocess inherits the current working directory of the current process.Parameters:
    command - a specified system command.
    envp - array of strings, each element of which has environment variable settings in format name=value.
    dir - the working directory of the subprocess, or null if the subprocess should inherit the working directory of the current process.
    Returns:
    a Process object for managing the subprocess.
      

  2.   

    谢谢两位,我知道第三个参数指的路径
    但是现在我不能用null,而指定一个具体的路径所以我其中的file的定义为:File file=new File("E:/yjyang/myketi/build.xml");为什么有错呢?
      

  3.   

    你这里的file定义的是一个文件(build.xml文件)
    不要指定文件名,file就可以代表一个路径把File file=new File("E:/yjyang/myketi/build.xml");
    改成:File file=new File("E:/yjyang/myketi/");
    就可以了
    但要保证你的antTest.java文件在E:/yjyang/myketi/目录下
    否则会报错说找不到文件的
      

  4.   

    楼主试试这样呢:
    outputArea.append("start...\n");
    String[] cmd = new String[3];

    cmd[0] = "cmd.exe";//如果是win98的话 cmd[0]="command.com "; linux是"/bin/sh";
    cmd[1] = "/C"; 
    cmd[2] = "javac antTest.java";

    Runtime rt = Runtime.getRuntime();
    Process ps = rt.exec(cmd);我这样就没包错了哦:)