Write to a text file at a specific line

sjn78

Well-known member
Joined
May 4, 2003
Messages
255
Location
Australia
I need to be able to write to a specific line in a text file.

I can get the line number where I want the text to go, but actually writing to that line is the problem.

If anyone can help me out it would be great.

Thanks

Steve
 
You must read the whole file in, change the line and then write the whole file out again.

If this could cause memory problems, you can always write out the new file as youre reading the old one in on the fly. Either way, theres no way of directly replacing a line in a file.
 
Ok, I thought there was a way to loop throught the file then stop at the specific line, then change it.

I am actually trying tp write an ini file, but I have read xml files are better to use know but I have no idea where to start with them.

Are there any good places with examples of them to help me get started?

Thanks

Steve
 

Similar threads

C
Replies
0
Views
63
Cas Raj
C
S
Replies
0
Views
57
sva0008
S
E
Replies
0
Views
242
Eldeeb92
E
Back
Top