C#文件合并的方法
程序员文章站
2023-12-09 19:48:27
本文实例讲述了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#程序设计有所帮助。