当前位置:首页 > 职业技能 > 计算机证书

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

来源:小学无忧 作者: 2017-06-15


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);

  }

猜你喜欢
    无相关信息