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

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

全部回复(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
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!