Can we rewrite a single line of a textfile and then save it and close it?
For example, i need to rewrite the first line, and keep all the others. Is there a function to do this or do i have to copy the whole file after changing a single line?
My file contains more than a thausand lines, and i only need to change the first line.
Example of file:
test;test1;test2
other;other;other
other;other;other
x1000
and then
something;something;something
other;other;other
other;other;other
x1000
See what i mean? I just want to keep my file like it is but change the first line. I could copy the whole file and paste it after i changed the first line but i wonder if there a method already included in delphi to only change a particular line in a text file. Thanks!
This is not possible. Files are stored linearly and do not support insertion. If your line was a fixed length, then you could overwrite it. However, you wish to replace the line with new content that is longer. That cannot be done. You'd need to re-write the entire file.
A database may be more appropriate for your needs than a text file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With