使用FileStream实现多媒体文件的复制(二进制文件读写)

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (FileStream fsRead = new FileStream(@"D:\123.avi", FileMode.OpenOrCreate, FileAccess.Read))//被复制文件
            {
                using (FileStream fsWrite = new FileStream(@"E:\123.avi", FileMode.OpenOrCreate, FileAccess.Write))//复制文件
                {
                    byte[] buf = new byte[1024 * 1024 * 5];
                    while (true)
                    {
                        int r = fsRead.Read(buf, 0, buf.Length);
                        if (r == 0)
                        {
                            break;
                        }
                        fsWrite.Write(buf, 0, r);//写入
                    }
                }
            }

        }
    }
}

 

你可能感兴趣的:(c#)