using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; //添加命名空间
using System.IO; namespace 文件流
{
class Program
{
static void Main(string[] args)
{
string source = @"C:\Users\Administrator\Desktop\增加.gif"; string target = @"C:\Users\Administrator\Desktop\new.gif"; Command.CopyFile(source, target); Console.WriteLine("复制成功!"); Console.ReadKey();
}
} //操作类
public class Command
{
public static void CopyFile(string source, string target)
{
//创建读取流
using(FileStream fsRead = new FileStream(source, FileMode.Open, FileAccess.Read))
{
//创建写入流
using(FileStream fsWrite = new FileStream(target, FileMode.OpenOrCreate, FileAccess.Write))
{
//字节数组,存放取出的字节数
byte[] buffer = new byte[ * * ]; //循环,当i!=0的时候循环
while (true)
{
//当前是假存到字节数组中的字节数
int i = fsRead.Read(buffer, , buffer.Length); //如果i==0,break;
if (i == )
{
break;
} //写入数据
fsWrite.Write(buffer, , i);
}
}
}
}
}
}