using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace MoveFileTest
{
class Program
{
static void Main(string[] args)
{
//思路:先将要复制的多媒体文件读取出来,然后在写入到指定位置
string source = @"C:\Users\pengshiyu\Desktop\source\微信图片_20170709221953.jpg";
string target = @"C:\Users\pengshiyu\Desktop\source\微信图片.jpg";
CopyFile(source,target);
Console.WriteLine("多媒体文件复制成功");
Console.ReadKey();
}
public static void CopyFile(string source, string target)
{
//1、创建一个负责读取的流
using (FileStream fsRead = new FileStream(source, FileMode.Open, FileAccess.Read))
{
//2、创建一个写入流
using (FileStream fsWrite = new FileStream(target, FileMode.OpenOrCreate, FileAccess.Write))
{
//3、多媒体文件较大,循环读取
byte[] buffer = new byte[1024 * 1024 * 5];//5M
while (true)
{
//返回本次读取实际读取到的字节数
int r = fsRead.Read(buffer, 0, buffer.Length);
//如果返回0,什么也没读取到
if (r == 0) break;
fsWrite.Write(buffer,0,r);//最后一次读取,可能不是5M
}
}
}
}
}
}