C#自适应合并文件的方法
更新时间:2015年07月07日 14:39:06 作者:DTC2
这篇文章主要介绍了C#自适应合并文件的方法,涉及C#基于FileStream类实现文件读写操作的相关技巧,非常简单实用,需要的朋友可以参考下
本文实例讲述了C#自适应合并文件的方法。分享给大家供大家参考。具体实现方法如下:
using System;
using System.IO;
namespace MergeFile
{
class Program
{
public static void Main(string[] args)
{
int count=1;
string sourcepath=@"D:\SplitFile";
string filetomerge=@"C:\编程的奥秘.pdf";
FileStream ftm = new FileStream(filetomerge, FileMode.Create, FileAccess.Write);
BinaryWriter bw=new BinaryWriter(ftm);
string filepath;
while(File.Exists(filepath=sourcepath+Path.DirectorySeparatorChar+Path.GetFileName(filetomerge)+count++))
{
FileStream fsr = new FileStream(filepath, FileMode.Open, FileAccess.Read);
BinaryReader br=new BinaryReader(fsr);
bw.Write(br.ReadBytes((int)fsr.Length));
br.Close();
fsr.Close();
}
bw.Flush();
bw.Close();
ftm.Close();
}
}
}
希望本文所述对大家的C#程序设计有所帮助。
您可能感兴趣的文章:
相关文章
关于C#连接SQL Server时提示用户登录失败的解决方法
在用C#开发windows端程序并连接SQL Server时有可能会遇到数据库登录失败的问题,下面小编给大家带来了C#连接SQL Server时提示用户登录失败的解决方法,感兴趣的朋友一起看看吧2021-11-11


最新评论