问题 单项选择题

正确生成RandomAccessFile对象的语句是 ( )

A.File f=new File("readFile"); RandomAccessFile raF=newRandomAeeess Filel(;

B.RandomAccessFile raF=new RandomAcccssFile(d:\mydir\File3.txt,"rw");

C.RandomAccessFile raF=new RandomAccessFile("readwriteFile","rw");

D.RandomAccessFile raF=new RandomAccessFite("readwriteFile",r

答案

参考答案:C

解析: 本题考查随机文件流的概念。文件操作中经常需要的是随机访问,Java中的RandomAccessFile类提供了随机访问文件的功能,它继承了Object类,用DataInput和 DataOutput接口来实现。接口中定义了从流中读/写基本类型的数据方法。因此也可随机读入数据文件的记录。一个随机文件建立的语句为:RandomAccessFile raF=new RandomAccessFile("readwriteFile","rw");其中"rw"表示可读写,所以选项C正确。

单项选择题
单项选择题