title: What is the best way to merge large files?
body: <p>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?</p>
  
  <p>Using File.AppendAllLines</p>
  
  <pre><code>for (int i = 0; i &lt; countryFiles.Length; i++){
     string srcFileName = countryFiles[i];
     string[] countryExtractLines = File.ReadAllLines(srcFileName);  
     File.AppendAllLines(actualMergedFileName, countryExtractLines);
  }
  </code></pre>
  
  <p>Using Stream.CopyTo</p>
  
  <pre><code>using (Stream destStream = File.OpenWrite(actualMergedFileName)){
    foreach (string srcFileName in countryFiles){
      using (Stream srcStream = File.OpenRead(srcFileName)){
          srcStream.CopyTo(destStream);
      }
    }
  }
  </code></pre>