简体   繁体   English

如何在Java文本文件中附加现有行

[英]How to append existing line within a java text file

I'm having trouble adding to an exsisting line in a text file without overwriting that particular line or adding a new line. 我无法在不覆盖特定行或添加新行的情况下添加到文本文件中的现有行。

for example, i have a line in my text file which is: 例如,我的文本文件中有一行:

hello my name is

I would like to add to this line so it becomes: 我想添加到此行,使其变为:

hello my name is joe bloggs

Thanks 谢谢

i have a task to create a help desk program and i am trying to incorporate a feature that enables users to edit questions they have posted. 我有一个创建帮助台程序的任务,并且我正在尝试合并一项功能,使用户可以编辑他们发布的问题。 as a result, the program will need to be able to append Any line within the text file - not necessarily just the last line 结果,程序将需要能够在文本文件中附加任何行-不一定只是最后一行

If it's not at the end of the file, you're in trouble - you're basically talking about inserting data in the middle of a file, which isn't traditionally supported by file systems. 如果它不在文件末尾,那么您就很麻烦-您基本上是在谈论在文件中间插入数据,而文件系统通常不支持这种插入

The normal way to approach this is to create a new file - copy the portion before the insertion point from the old file, then write your new data, then copy the remainder of the original file afterwards. 解决此问题的通常方法是创建一个文件-从旧文件复制插入点之前的部分,然后写入新数据,然后再复制原始文件的其余部分。 Finally, do whatever renaming/deleting you need. 最后,进行所需的重命名/删除操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM