namespace _07_File和FileStream {
class Program {
static void Main(string[] args) {
string sourcePath = @"C:\Users\Gerton\Desktop\源文件.mp3";
string targetPath = @"C:\Users\Gerton\Desktop\目标文件.mp3";
myCopy(sourcePath, targetPath);
Console.ReadKey();
}
public static void myCopy(string sourcePath,string targetPath) {
using (FileStream fileRead = new FileStream(sourcePath, FileMode.Open, FileAccess.Read)) {
using(FileStream fileWrite = new FileStream(targetPath, FileMode.OpenOrCreate, FileAccess.Write)) {
byte[] buffer = new byte[1024 * 1024];
while (true) {
int r = fileRead.Read(buffer, 0, buffer.Length);
if (r == 0) {
break;
}
fileWrite.Write(buffer, 0, r);
}
}
}
}
}
}
转载请注明原文地址:https://ipadbbs.8miu.com/read-57937.html