java.io.RandomAccessFile

来源:互联网 发布:dnf老是网络中断2016 编辑:程序博客网 时间:2024/05/01 21:33

 用途:文件的随机读写

定义:public clasee RandomAccessFile extends Object implement DataInput,DataOutput

构造涵数:

1、public RandomAccessFile(File file,String mode).

    (1)file:一个文件对象

    (2)读写模式  r=只读

                                 w=只写

                                rw=可读写

                                rws=

                                rwd=

2.   public RandomAccessFile(String fileName,String mode).

    (1) String name:要读写的文件名

 

常用方法

1.public void seek(long pos) throws IOException

    (1)功能:移动文件指针到pos指定的位置

2.public long getFilePointer() throws IOException

    功能:获取文件指针的位置,是相对于文件起始位置的偏移量,以字节为单位。

3.public final String readLine() throws IOException

    返回该文件下一行的文本,如文件已经结否,则返回null.

文件指针遵循的规律:

1、新建文件时,位于文件的开头。

2、读写操作后,后移到读写的字节数。