inserting data in the middle of a text file through java

断了今生、忘了曾经 提交于 2019-12-29 08:05:07

问题


I want to insert the data at some positions in the text file without actually overwriting on the existing data.I tried RandomAccessFile ....but that also overwrites it.... Is there any way to insert the data without overwriting?? -Thanks in advance


回答1:


You have to read your file and rewrite it. During this operation you have to find the place where you want to put your text and write it.




回答2:


It is not possible (not with Java, and not with any other programming language) to "just" insert data in the middle of the file, without having to re-write the rest of the file. The problem is not the programming language, the problem is the way files work.



来源:https://stackoverflow.com/questions/3743395/inserting-data-in-the-middle-of-a-text-file-through-java

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!