Writing to a particular position

  • Thread starter Thread starter lexicon
  • Start date Start date
L

lexicon

Hello;
I have a text file. Assume that this file has some textual content. I
want to append a text into this file at a specific position; not to the
end of file. I assume that one way of doing this would be setting the
stream length, shifting the characters after the position + lengt to
the end, but this method seems inefficient to me. Another way might be,
storing the text content in an array and manipulating and writing this
array to the file, but this seems inefficient to me too.
Is there any way of doing this without the methods i thought about
above ? All ideas are appreciated, thank you very much...
 
One way to do it is to read the file into a StringBuilder object.
StringBuilder provides an effecient way to manipulate string. Alternatively,
you can also treat your text file as a raw stream of bytes, and manipulate
it using the FileStream object, however I think this will be a bit more
trickier.

-- Ricky Lee
==================================================
^o^ "When all doors are closed, God will open a Windows" ^o^
==================================================
 
Back
Top