using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace Filestream複製視頻文件 { class Program { st ...
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);
}
}
}
}
}
}