Java随机访问RandomAccessFile类

Java的RandomAccessFile类

构造函数

例:

   File file=new File("path");
   RandomAccessFile in=new RandomAccessFile(file,"rw");
   //"rw"	打开以便读取和写入。如果该文件尚不存在,则尝试创建该文件。

参数介绍

除了“rw”以外还有:
"r" Open for reading only. Invoking any of the write methods of the resulting object will cause an IOException to be thrown.

"rw" Open for reading and writing. If the file does not already exist then an attempt will be made to create it.

"rws" Open for reading and writing, as with “rw”, and also require that every update to the file’s content or metadata be written synchronously to the underlying storage device.

"rwd" Open for reading and writing, as with “rw”, and also require that every update to the file’s content be written synchronously to the underlying storage device.

r” 只供阅读。调用结果对象的任何写方法都会导致抛出IOException。

rw” 打开以便读取和写入。如果该文件尚不存在,则尝试创建该文件。

rws” 可用于读写,并要求对f ile的内容或元数据的每次更新都要同步写入底层存储设备。

rwd” 可用于读写,并要求对文件内容的每次更新都要同步写入底层存储设备。

//作者:yuxiang
见图如见人

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值