C#文件合并

来源:互联网 发布:股票走势软件 编辑:程序博客网 时间:2024/06/05 03:41

[代码] 文件合并

 

http://www.oschina.net/code/snippet_222150_8304

 

 
01using System;
02using System.IO;
03string filetomerge=@"C:\temp\data.bin";
04string targetpath=@"D:\store";
05string strFileName = filetomerge.Substring(filetomerge.LastIndexOf(Path.DirectorySeparatorChar) + 1);
06FileStream fsr1 = new FileStream(targetpath+ Path.DirectorySeparatorChar + strFileName + "1", FileMode.Open, FileAccess.Read);
07FileStream fsr2 = new FileStream(targetpath+ Path.DirectorySeparatorChar + strFileName + "2", FileMode.Open, FileAccess.Read);
08byte[] btArr = new byte[fsr1.Length+fsr2.Length];
09fsr1.Read(btArr, 0, Convert.ToInt32(fsr1.Length));
10fsr2.Read(btArr, Convert.ToInt32(fsr1.Length), Convert.ToInt32(fsr2.Length));
11fsr1.Close();
12fsr2.Close();
13FileStream fsw = new FileStream(%%2 + Path.DirectorySeparatorChar+ strFileName, FileMode.Create, FileAccess.Write);
14fsw.Write(btArr, 0, btArr.Length);
15fsw.Flush();
16fsw.Close();