什么是用C#来连接三个文件的最快方法? [英] What would be the fastest way to concatenate three files in C#?

查看:103
本文介绍了什么是用C#来连接三个文件的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用C#来连接3个文件。头文件,内容和页脚文件,但我想这样做凉爽,因为它可以做到的。

酷=真小code或非常快(非组装code)。


解决方案

 无效CopyStream(流的目的,流源){
   诠释计数;
   字节[]缓冲区=新的字节[BUFFER_SIZE];
   而((计数= source.Read(缓冲液,0,buffer.Length))大于0)
       destination.Write(缓冲,0,计数);
}
CopyStream(outputFileStream,fileStream1);
CopyStream(outputFileStream,fileStream2);
CopyStream(outputFileStream,fileStream3);

I need to concatenate 3 files using C#. A header file, content, and a footer file, but I want to do this as cool as it can be done.

Cool = really small code or really fast (non-assembly code).

解决方案

void CopyStream(Stream destination, Stream source) {
   int count;
   byte[] buffer = new byte[BUFFER_SIZE];
   while( (count = source.Read(buffer, 0, buffer.Length)) > 0)
       destination.Write(buffer, 0, count);
}


CopyStream(outputFileStream, fileStream1);
CopyStream(outputFileStream, fileStream2);
CopyStream(outputFileStream, fileStream3);

这篇关于什么是用C#来连接三个文件的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆