import java.io.*;
public class IOExa3 
{ public static void main(String[] args)
{  try
    {  Runtime ce=Runtime.getRuntime();
  ce.exec("javac BollTest.java");
   ce.exec("java BollTest");
   File file=new File("G:/java code/jackxu/src","BollTest.java");
   ce.exec(file.getAbsolutePath());
    }

            catch(Exception e)
             { System.out.println(e);
       
              }
} }
上述程序是打开记事本G:/java code/jackxu/src下的BollTest.java,然后运行,但是记事本带不开,程序也报错。把 File("G:/java code/jackxu/src","BollTest.java")里面的参数换成("C:/windows" ,"Notepad.exe")能够打开windows平台的记事本,把BollTest.java程序代码直接复制到里面,无论存到什么盘,打开的记事本都是空的?这个该怎么改,才能打开记事本,运行里面的程序?

解决方案 »

  1.   

    RunTime启动的就应该是Notepad.exe。但要把 G:/java code/jackxu/src/BollTest.java 这个字符串,作为启动参数给Notepad.exe。
      

  2.   


    ce.exec("Notepad G:/java code/jackxu/src/BollTest.java");
      

  3.   

    打开之后,怎样让程序编译,运行?
    ce.exec("javac BollTest.java");
    ce.exec("java BollTest");
    这两句怎样让它起作用?
      

  4.   

    应该这样就可以了。
    ce.exec("javac G:/java code/jackxu/src/BollTest.java");
    ce.exec("java G:/java code/jackxu/src/BollTest");
    要设置path和classpath环境变量。
      

  5.   

    环境变量设了,classpath:
                G:\JDK7.0\jre\lib\rt.jar;.;
               path:
                G:\JDK7.0\bin;
          用命令提示符能过编译BollTest.java。在程序中打开了BollTest.java所在的记事本后,怎么没有任何反应??
      

  6.   

    ce.exec("javac BollTest.java");
    ce.exec("java BollTest");
    指定javac和java的完整路径