Add bytes to filestream in specific place

otherside

Well-known member
Joined
Mar 16, 2003
Messages
127
Location
UK - Greece
Hey guys
Is there any way to add some bytes to a specific place in a file WITHOUT reading all the file in the memory ?
Assume that the file is very large up to 200Mb
i tried to use the append mode in conjuction with seek, but i get an exception that you cant seek in append mode
so i assume thats not the way to do it
Code:
        Dim Fstr As New FileStream("test.txt", FileMode.Append)
        Dim data(10) As Byte
        Fstr.Seek(50, SeekOrigin.Begin)
        Fstr.Write(Data, 0, 10)
Any ideas ?
 
If you think about it, inserting bytes like that would mean physically moving the rest of the file (could be hundreds of megs) up by that number of bytes. You just cant do things like that.
 
Divil, thanks for your reply
i know that, and i know in depth about that stuff, but there should be a way to do it.
I mean how all the other applications can.
Lets take the simplest winamp, when you changing a id3v2 tag it increases the size of the file instantly to write the information on the start of the file ?
I know winamp is actually built on C++ (And i actually know how to do it in c) but there should be some class in the whole .net framework that does that.
 
Winamp still has to rebuild the file when it wants to insert or remove data from the middle of a file. All applications do, it is the nature of our file system. There is no way to get around it.
 
Back
Top