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
見圖如見人

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