大家讲道理2017-04-17 14:24:26
答案是不能。
RandomAccessFile
其中這一句話
output operations write bytes starting at the file pointer and advance
the file pointer past the bytes written
RandomAccessFile 將檔案視為一個byte數組,它修改其中某個位置的值的行為就是,將第i個位置的值寫為一個新的值,然後將指標指向後一個元素。
可以看出,這個類別不會幫你完成所有剩餘的值進行移位的功能。所以如果你需要完成「插入」的功能,需要自己把陣列的後續內容讀取出來,重新依序寫入檔案。
stackoverflow參考: