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