本帖最后由 t1o4m5 于 2011-11-24 22:33:24 编辑

解决方案 »

  1.   

    import java.io.BufferedReader;
    import java.io.File;
    import java.io.IOException;
    import java.io.InputStreamReader;public class Compile {
      private String mess = null;
      private File file;
      private Runtime run;
      private Process pro;
      public static void main(String[] args) throws InterruptedException{
      Compile com = new Compile();
    com.setFile(new File("D:\\Test\\Java23"));
    System.out.println(com.isCompile());
      }  public Compile() {
      this.run = Runtime.getRuntime();
      }  public void setFile(File file) {
      this.file = file;
      }  public String isCompile() throws InterruptedException {
      try {
      System.out.println(this.file.getPath());
      this.pro = this.run.exec("cmd.exe /c javac " + this.file.getPath() + ".java");
      BufferedReader buf = new BufferedReader(new InputStreamReader(this.pro.getErrorStream()));
      String str;
      while ((str = buf.readLine()) != null) {
      mess += str + "\n";
      }  if (null == this.mess) {
      this.mess = "编译成功";
      }
      return mess;
      } catch (IOException ex) {
      return ex.getMessage();
      }
      }
    }
      

  2.   

    怎么解决的啊。我现在也遇到这样的问题,查找java的版本号,没有结果