首页>计算机等级>导航 > 备考辅导

2017年计算机二级考试java章节辅导:例程:显示一个文件

2017-06-15 15:51:00 来源:无忧考网

9.6 例程:显示一个文件

  如果文件的访问权限足够,你可以在TextArea对象里显示文件内容。

  下面是显示文件的程序片断:

  FileInputStream fis;

  TextArea ta;

  public vod init(){

  byte b[] = new byte [1024];

  int I; //make it big enough or wait until you //know the size of the file String s;

  try {

  fis = new FileInputStream("/etc/motd");

  }

  catch(FileNotFoundException e) {

  /*do something appropriate */

  }

  try {

  I= fis.read(b);

  }

  catch(IOException e) {

  /* do something appropriate */

  }

  s = new String(b, 0);

  ta = new TextArea(s,5,40); add (ta);

  }

计算机等级最新更新
推荐阅读
网站首页 网站地图 返回顶部
无忧考网移动版
京公网安备 11010802026788号