How do I use the Stream CopyTo method without overwriting the existing output file?
public void MergeAndDeleteFiles(string outputFile, IEnumerable<string> inputFiles)
{
using (var output = File.OpenWrite(outputFile))
{
foreach (var inputFile in inputFiles)
{
using (var input = File.OpenRead(inputFile))
{
input.CopyTo(output);
}
}
}
}
The above method overwrites the outputFile for some reason? DO i need to set the position of the output file before using the CopyTo method?
Instead of
OpenWriteuseOpenand pass inFileMode.Append:This will append the output to the end of the file.