? 前面学习的文件输入流和文件输出流都是单向的,流中的数据必须按顺序
进行读写
? 在某些情况下,程序需要不按照顺序随机地访问磁盘文件中的内容
? Java提供了专门用来处理文件随机存取的类RandomAccessFile
RandomAccessFile
----用来随机读取文件,其功能更完善
----类直接隶属于Object类
----类创建的流的指向既可以作为源,
也可以作为目的地
? public RandomAccessFile(String name, String mode)
throws FileNotFoundException
? public RandomAccessFile(File file, String mode)
throws FileNotFoundException
第二个参数mode取值:
“r”— 以只读方式打开文件
“rw” —以读写方式打开文件
? public long getFilePointer() throws IOException
返回当前文件指针
? public void seek(long pos) throws IOException
把文件指针置于给出的位置pos
? public long length() throws IOException
返回文件长度
? public int skipBytes(int n) throws IOException
从当前位置开始跳过n个字节