Filestream复制视频文件

时间:2023-03-08 21:21:46

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Filestream复制视频文件
{
class Program
{
static void Main(string[] args)
{
//要复制的文件路径
string yuan = @"F:\old.MP4";
//复制位置的路径
string xian = @"C:\Users\Administrator\Desktop\new.MP4";

//创建读取的流
using (FileStream fsread = new FileStream(yuan, FileMode.Open, FileAccess.Read))
{
//创建写入的流
using (FileStream fswrite = new FileStream(xian, FileMode.OpenOrCreate, FileAccess.Write))
{
byte[] buffer = new byte[1024 * 1024 * 5];
//因为文件可能比较大,所以我们在读取的时候应该循环的读取
while (true)
{
//返回实际读取到的字节数
int r = fsread.Read(buffer, 0, buffer.Length);
//如果返回的是一个0,也就是读完了
if (r == 0)
{
break;
}

fswrite.Write(buffer, 0, r);
}
}
}
}
}
}