Объединить несколько файлов в один - C#
Формулировка задачи:
Такой вопрос. Дано множество файлов txt, в них таблицы типа
Как с помощью с# соединить их в один txt файл типа
Имя(таб)возраст(таб)пол(таб)телефон(таб)дата вася(таб)40(таб)м(таб)98756(таб)10.01.2015 ...(таб)...(таб)...(таб)...(таб)...
Имя(таб)возраст(таб)пол(таб)телефон(таб)дата вася(таб)40(таб)м(таб)98756(таб)10.01.2015 ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)... ...(таб)...(таб)...(таб)...(таб)...
Решение задачи: «Объединить несколько файлов в один»
textual
Листинг программы
using System;
using System.IO;
using System.Text;
namespace cyb31 {
class Program {
static void Main(string[] args) {
string strPath=Environment.CurrentDirectory;
string strOut = strPath + @"\out.txt";
bool isTop = true;
using (StreamWriter sw = new StreamWriter(strOut, true, Encoding.GetEncoding("Windows-1251"))) {
foreach (string strFile in Directory.GetFiles(strPath, @"*.txt"))
if (strOut != strFile)
using (StreamReader sr = new StreamReader(strFile, Encoding.GetEncoding("Windows-1251"))) {
int cnt = 1;
while (sr.Peek() > -1)
if ((cnt++) == 1 && !isTop) {
sr.ReadLine();
continue;
} else
sw.WriteLine(sr.ReadLine());
isTop = false;
}
}
}
}
}