_04媒体文件的读取

 1 using System;
 2 using System.Collections.Generic;
 3 using System.IO;
 4 using System.Linq;
 5 using System.Text;
 6 using System.Threading.Tasks;
 7 
 8 namespace _04媒体文件的读取
 9 {
10     class Program
11     {
12         //***************************第一种读取的方式:********************
13         static void Main(string[] args)
14         {
15             string path = @"C:\Users\Administrator\Desktop\震撼宇宙.mp4";
16             string newpath = @"C:\Users\Administrator\Desktop\震撼宇宙(1).mp4";
17             IsMove(path, newpath);
18         }
19         public static void IsMove(string path,string newpath)
20         {
21             using (FileStream movRead=new FileStream(path,FileMode.OpenOrCreate,FileAccess.Read))
22             {
23                 using (FileStream moveWrite=new FileStream(newpath,FileMode.OpenOrCreate,FileAccess.Write))
24                 {
25                     //读的时候要先创造个容器 来一次读多少
26                     byte[] bt = new byte[1024 * 1024 * 5];
27                     while (true)//一次不能读完,得几次读取,知道读完,所以用while
28                     {
29                        int num= movRead.Read(bt, 0, bt.Length);//一次不呢读完,就返回每次实际读取的长度
30                         if (num==0)
31                         {
32                             break;
33                         }
34                         moveWrite.Write(bt, 0, num);//读取多少就写如多少
35                     }
36                 }
37             }
38         }
39     }
40 }

 

posted @ 2018-09-19 18:52  白纸菇凉  阅读(138)  评论(0编辑  收藏  举报