I have to merge thousands of large files (~200MB each). I would like to know what is the best way to merge this files. Lines will be conditionally copied to the merged file. Could it by using File.AppendAllLines or using Stream.CopyTo?
Using File.AppendAllLines
for (int i = 0; i < countryFiles.Length; i++){
string srcFileName = countryFiles[i];
string[] countryExtractLines = File.ReadAllLines(srcFileName);
File.AppendAllLines(actualMergedFileName, countryExtractLines);
}
Using Stream.CopyTo
using (Stream destStream = File.OpenWrite(actualMergedFileName)){
foreach (string srcFileName in countryFiles){
using (Stream srcStream = File.OpenRead(srcFileName)){
srcStream.CopyTo(destStream);
}
}
}