您的位置:首页 > 编程语言 > C#

C#实现各种格式文件的复制

2015-11-17 20:58 190 查看
<span style="white-space:pre">	</span>//<span style="white-space:pre">	</span>string path1 = @"F:\unity生命周期.png";
//<span style="white-space:pre">	</span>string path2 = @"E:\unity生命周期.png";
//<span style="white-space:pre">	</span>FileCopy (path2, path1);
//实现文件复制
void FileCopy(string path1, string path2)
{
int bufferSize = 10240;

Stream source = new FileStream (path1, FileMode.Open, FileAccess.Read);
Stream target = new FileStream (path2, FileMode.Create, FileAccess.Write);

byte[] buffer = new byte[bufferSize];
int bytesRead;
do {
bytesRead = source.Read (buffer, 0, bufferSize);
target.Write (buffer, 0, bytesRead);
} while(bytesRead > 0);

source.Dispose();
target.Dispose();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: