//定义源文件和目标文件,绝对路径
public static string source = @"E:\C#\C#编程语言详解.pdf";
//2014-6-10 Training
//拷贝大文件,分块拷贝
AddBigFile(source);
/// <summary>
/// 拷贝大文件
/// </summary>
/// <param name="source">原绝对路径</param>
private static void AddBigFile(string source)
{
int i = ;
using (FileStream fsRead = new FileStream(source, FileMode.Open))
{
byte[] byts = new byte[ * * ];
while (true)
{
int r = fsRead.Read(byts, , byts.Length); if (r <= )
{
Console.WriteLine("----End----");
break;
}
DataBaseController.AddFiles(source, i, byts);
Console.WriteLine("FileName:" + source + "第 " + i + "个" + "大小:" + byts.Length);
i++;
}
}
} DataBaseController.AddFiles函数是拿到二进制数据,插入数据库操作: public static class DataBaseController
{
public static readonly string connstr = "Data Source=.;Initial Catalog=AddFile;Persist Security Info=True;User ID=sa;Password=sa";
public static string Tosource = @"E:\C#\Copy123C#编程语言详解.pdf"; public static void AddFiles(string FileName,int Code,byte[] Data)
{
string sql = @"insert into FileBlock(FileName, Code, Data) values(@FileName, @Code, @Data)";
DateTime time = DateTime.Now;
SqlParameter[] pars = {
new SqlParameter("@FileName",FileName),
new SqlParameter("@Code",Code),
new SqlParameter("@Data",Data) };
int count = SqlHelper.ExecuteNonQuery(connstr, CommandType.Text, sql, pars);
} public static void GetFilesByName(string FileName)
{
string sql = @"select * from FileBlock where FileName = @FileName";
DateTime time = DateTime.Now;
SqlParameter[] pars = {
new SqlParameter("@FileName",FileName),
};
List<FileBlock> list = new List<FileBlock>();
using (SqlDataReader reader = SqlHelper.ExecuteReader(connstr, CommandType.Text, sql, pars))
{
list = Application.Data2Objects<FileBlock>(reader);
} //循环查出文件的多个块,拼接写在一个文件中
FileStream fs = new FileStream(Tosource,FileMode.Create);
foreach (var item in list)
{
fs.Write(item.Data,,item.Data.Length);
} //byte[] data = new byte[fs.Length];
//fs.Read(data,0,fs.Length);
//fs.Seek(0,SeekOrigin.Begin);
// return data;
}
} public class FileBlock
{
public int ID { get; set; }
public string FileName { get; set; }
public int Code { get; set; }
public byte[] Data { get; set; }
}

最新文章

  1. json使用
  2. Android点击效果
  3. LCS(Longest Common Subsequence 最长公共子序列)
  4. 有关git的换行符的处理问题
  5. Bootstrap日期和时间表单组件运用兼容ie8
  6. 曝光卖假币的店铺和旺旺ID
  7. ruby 模块 的引入
  8. C++PRIMER 阅读笔记 第三章
  9. Udacity并行计算课程笔记-The GPU Programming Model
  10. 使用kafka connect,将数据批量写到hdfs完整过程
  11. java集合HashMap、HashTable、HashSet详解
  12. IntelliJ IDEA 最新激活码
  13. listview--Java泛型应用之打造Android万能ViewHolder-超简洁写法
  14. jumpserver笔记
  15. 应用间共享文件 FileProvider
  16. 步步为营-10-string的简单操作
  17. squid 快速配置
  18. github优秀前端项目分享(转)
  19. 大数据开发实战:Hadoop数据仓库开发实战
  20. python学习笔记(二十九)为什么python的多线程不能利用多核CPU

热门文章

  1. Java爬虫系列一:写在开始前
  2. Eclipse下tomcat输出路径配置
  3. jmeter beanshell Typed variable declaration : Object constructor错误
  4. POJ2758 Checking the Text 哈希
  5. P2062 分队问题(贪心orDP)
  6. myeclipse非正常关闭处理办法
  7. Linux中ext2文件系统的结构
  8. HDU 5505——GT and numbers——————【素数】
  9. 冷笑话,idea 按删除键就是undo?
  10. asp.net 中@Html.Partial,@Html.Action,@Html.RenderPartial,@Html.RenderAction