//这个程序用于实现复制一个文件。
using System;
using System.IO;
class CopyFile {
public static void Main(string[] args){
string s1,s2;
int i ;
FileStream fin,fout;
Console.WriteLine("input file_1 name:");
s1 = Console.ReadLine();
Console.WriteLine("output file_2 name:");
s2 = Console.ReadLine();
try {fin = new FileStream(s1,FileMode.Open);}
catch (FileNotFoundException exc){ Console.WriteLine(exc.Message + "\nthe file is not found");return ;}
//open output file
try {fout = new FileStream(s2, FileMode.Create); }
catch (IOException exc){ Console.WriteLine(exc.Message + "\nError opening output file"); return ; }
//copy file
try {
do {
i=fin.ReadByte();
fout.WriteByte((byte)i);
} while (i!=-1);
}
catch (IOException exc){ Console.WriteLine(exc.Message + "\nError "); return ;}
}
}
c#复制文件
最新推荐文章于 2023-02-17 11:05:27 发布