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
见图如见人

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章