I would like to append a byte array to an already existing file (C:\test.exe)
. Assume the following byte array:
byte[] appendMe = new byte[ 1000 ] ;
File.AppendAllBytes(@"C:\test.exe", appendMe); // Something like this - Yes, I know this method does not really exist.
I would do this using File.WriteAllBytes, but I am going to be using an ENORMOUS byte array, and System.MemoryOverload exception is constantly being thrown. So, I will most likely have to split the large array up into pieces and append each byte array to the end of the file.
Thank you,
Evan
One way would be to create a
FileStream
with theFileMode.Append
creation mode.This would look something like:
I'm not exactly sure what the question is, but C# has a
BinaryWriter
method that takes an array of bytes.BinaryWriter(Byte[])
Where
writeFinished
is true when all the data has been appended, andGetData()
returns an array of data to be appended.You can also use the built-in
FileSystem.WriteAllBytes Method (String, Byte[], Boolean)
.Set append to True to append to the file contents; False to overwrite the file contents. Default is False.
you can simply create a function to do this
FileStream
.Seek()
to the end.Write()
the bytes.Close()
the stream.