发布网友 发布时间:2022-04-23 14:12
共1个回答
热心网友 时间:2023-08-21 05:13
/// <summary>
/// 断点续传,每次调用该方法会从源文件断点续传
/// </summary>
/// <param name="fullName">文件完整路径</param>
private void ReadFile(string fullName)
{
//文件名称
string fileName = Path.GetFileName(fullName);
//保存文件完整路径
string saveFullName = Path.Combine(@"D:\systemInfo", fileName);
FileStream write = new FileStream(saveFullName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite);
FileStream read = File.OpenRead(fullName);// 以读的方式打开
//移动读取流的位置
read.Seek(write.Length, SeekOrigin.Begin);
byte[] bytes = new byte[1024];
int length = 0;
while ((length = read.Read(bytes, 0, bytes.Length)) > 0)
{
write.Write(bytes, 0, length);
}
write.Close();
read.Close();
}