java RandomAccessFile 覆盖数据
迷茫
迷茫 2017-04-17 14:22:26
0
1
1127
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

Antworte allen(1)
大家讲道理

答案是不能。
RandomAccessFile

其中这一句话

output operations write bytes starting at the file pointer and advance
the file pointer past the bytes written

RandomAccessFile 将文件视为一个byte数组,它修改其中某个位置的值的行为就是,将第i个位置的值写为新的值,然后将指针指向后一个元素。

可以看出,这个类不会帮你完成所有剩下的值进行移位的功能。所以如果你需要完成“插入”的功能,需要自己把数组的后续内容读取出来,重新按顺序写入文件。

stackoverflow参考:

  1. Inserting text in middle using RandomAccessFile removes some text after that
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!