20230625 java.io.RandomAccessFile

介绍

  • java.io.RandomAccessFile
  • public class RandomAccessFile implements DataOutput, DataInput, Closeable
  • 同时实现了 DataInput 和 DataOutput 接口
  • 可以在文件中的任何位置查找或写入数据

API

构造器

  • RandomAccessFile(String name, String mode) throws FileNotFoundException
  • RandomAccessFile(File file, String mode) throws FileNotFoundException
    • name : pathname ,表示文件路径
    • mode : 读写模式,r(用于读入访问 )或 rw (用于读入/ 写出访问),还有其他模式等
      • r 表示只读模式
      • rw 表示读/写模式
      • rws 表示每次更新时,都对数据和元数据的写磁盘操作进行同步的读/写模式
      • rwd 表示每次更新时,只对数据的写磁盘操作进行同步的读/写模式

public

  • read

    • int read() throws IOException
    • int read(byte b[]) throws IOException
    • int read(byte b[], int off, int len) throws IOException
  • getFilePointer

    • 返回文件指针的当前位置
  • seek

    • 将文件指针设置到距文件开头 pos 个字节处
  • length

    • 返回文件按照字节来度量的长度
  • setLength

  • getFD

  • getChannel

posted @ 2023-08-23 09:57  流星<。)#)))≦  阅读(6)  评论(0编辑  收藏  举报