Java RandomAccessFile随机访问类

本文介绍了Java中的RandomAccessFile类,详细讲解了其核心方法,并通过实例展示了如何使用该类进行文件的随机访问和拷贝操作,是Java文件操作的重要工具。
摘要由CSDN通过智能技术生成

Java RandomAccessFile随机访问类


介绍

Java的RandomAccessFile提供对文件的读写功能,与普通的输入输出流不一样的是RamdomAccessFile可以任意的访问文件的任何位置。RandomAccessFile的对象包含一个记录指针,用于标识当前流的读写位置,这个位置可以向前移动,也可以向后移动。



RandomAccessFile类最大的特点在于其具有可读与可写的功能并且可以任意访问文件任何位置,不像其他IO流通常只具备其中一种方法。从其继承结构就可以知道其拥有了很多读取和写入各种数据类型的方法。



Instances of this class support both reading and writing to a random access file. A random access file behaves like a large array of bytes stored in the file system. There is a kind of cursor,or index into the implied array, called the file pointer;input operations read bytes starting at the file pointer and advance the file pointer past the bytes read. If the random access file is created in read/write mode, then output operations are also available;output operations write bytes starting at the file pointer and advance the file pointer past the bytes written. Output operations that write past the current end of the implied array cause the array to be extended. The file pointer can be read by the getFilePointer method and set by the seek
method.

RandomAccessFile类核心方法

public class RandomAccessFile implements DataOutput, DataInput, Closeable {

    /**
     * Creates a random access file stream to read from, and opt
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值