日期:2014-05-20  浏览次数:20735 次

java中Runtime类的使用问题
import java.io.*;
public class IOExa3
  {
  public static void main(String[] args)
  { try
  { Runtime ce=Runtime.getRuntime();
InputStream in=ce.exec("javac IOExa1.java").getErrorStream();
  BufferedInputStream bin=new BufferedInputStream(in);
byte shuzu[]=new byte[100];
int n;
while((n=bin.read(shuzu, 0, 100))!=-1)
{ String s=null;
s=new String(shuzu,0,n);
compiler_text.append(s);
if(s!=null)
  boolean bn=false;
}
  if(bn)
  {compiler_text.append("编译正确");
  }
 
  }
  catch(IOException el){}
  }
 }
上面的程序是用eclipse编写的,compiler_text是TextArea的实例,实例化过程被我省略了.图形界面创建过程也省略了。运行程序后文本域compiler_text只显示了"编译正确",没有显示compiler_text.append(s);这儿是因为IOExa1.java编译成字节码后无法显示在compiler_text中,还是什么原因????



------解决方案--------------------
InputStream in=ce.exec("javac IOExa1.java").getErrorStream();
你是获取的错误信息,没有错的话也就没有数据了