欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

C#文件合并的方法

程序员文章站 2023-11-21 12:11:04
本文实例讲述了c#文件合并的方法。分享给大家供大家参考。具体实现方法如下: using system; using system.io; string fil...

本文实例讲述了c#文件合并的方法。分享给大家供大家参考。具体实现方法如下:

using system;
using system.io;
string filetomerge=@"c:\temp\data.bin";
string targetpath=@"d:\store";
string strfilename = filetomerge.substring(filetomerge.lastindexof(path.directoryseparatorchar) + 1);
filestream fsr1 = new filestream(targetpath+ path.directoryseparatorchar + strfilename + "1", filemode.open, fileaccess.read);
filestream fsr2 = new filestream(targetpath+ path.directoryseparatorchar + strfilename + "2", filemode.open, fileaccess.read);
byte[] btarr = new byte[fsr1.length+fsr2.length];
fsr1.read(btarr, 0, convert.toint32(fsr1.length));
fsr2.read(btarr, convert.toint32(fsr1.length), convert.toint32(fsr2.length));
fsr1.close();
fsr2.close();
filestream fsw = new filestream(%%2 + path.directoryseparatorchar+ strfilename, filemode.create, fileaccess.write);
fsw.write(btarr, 0, btarr.length);
fsw.flush();
fsw.close();

希望本文所述对大家的c#程序设计有所帮助。