concatenate files in C #

2

Good morning

I have several txt files in the same directory-frames-1, frames-2 ..., I just need to create one file. but with an aggravating fact that each file will be a column of the final file. as if it were an array. where each file is array column.

Someone could help me out

    
asked by anonymous 14.12.2015 / 16:06

1 answer

2

The performance way is like this:

const int chunkSize = 2 * 1024; // 2KB
var inputFiles = new[] { "marcos1.txt", "marcos2.txt", "marcos3.txt" };
using (var output = File.Create("marcos-juntos.txt"))
{
    foreach (var file in inputFiles)
    {
        using (var input = File.OpenRead(file))
        {
            var buffer = new byte[chunkSize];
            int bytesRead;
            while ((bytesRead = input.Read(buffer, 0, buffer.Length)) > 0)
            {
                output.Write(buffer, 0, bytesRead);
            }
        }
    }
}

I pulled it out .

    
14.12.2015 / 16:08