код:
static void MultipleFilesToSingleFile(string dirPath, string filePattern, string destFile)
{
string[] fileAry = Directory.GetFiles(dirPath, filePattern);
Console.WriteLine("Total File Count : " + fileAry.Length);
using (TextWriter tw = new StreamWriter(destFile, true))
{
foreach (string filePath in fileAry)
{
using (TextReader tr = new StreamReader(filePath))
{
tw.WriteLine(tr.ReadToEnd());
tr.Close();
tr.Dispose();
}
Console.WriteLine("File Processed : " + filePath);
}
tw.Close();
tw.Dispose();
}
}
Мне нужно оптимизировать это как чрезвычайно медленное: занимает 3 минуты для 45 файлов среднего размера 40 - 50 Мбайт XML файла.
Обратите внимание: 45 файлов в среднем 45 МБ - это всего лишь один пример, это может быть n
количество файлов размером m
, где n
находится в тысячах, а m
может быть в среднем 128 Кбайт, Короче говоря, он может меняться.
Не могли бы вы предоставить какие-либо мнения об оптимизации?