问题
单项选择题
正确生成RandomAccessFile对象的语句的是
A.File f=new File("readFile");
RandomAccessFile raF=new RandomAccessFile(f);
B.RandomAccessFile raF=new RandomAccessFile(d:\mydir\File3.txt,"rw");
C.RandomAccessFile raF=new RandomAccessFile("readwriteFile","rw");
D.RandomAccessFile raF=new RandomAceessFile("readwriteFile" ,rw);
答案
参考答案:C
解析: 本题考查随机文件流的概念。文件操作中经常需要的是随机访问,Java中的 RandomAccessFile类提供了随机访问文件的功能,它继承了Object类,用DataInput和DataOutput接口来实现。接口中定义了从流中读/写基本类型的数据方法。因此也可以随机读入数据文件的记录。一个随机文件建立的语句为:RandomAccessFile raF=new RandomAecessFile("readwriteFile","rw"):其中“~”表示可读写,所以选项C正确。