首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

java中Runtime类的使用有关问题

2012-04-10 
java中Runtime类的使用问题import java.io.*public class IOExa3{public static void main(String[] args

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();
你是获取的错误信息,没有错的话也就没有数据了

热点排行