static void Main(string[] args) { Console.WriteLine("请选择要打开的文件的路径"); string path = Console.ReadLine(); Console.WriteLine("请选择要打开的文件"); string fileName = Console.ReadLine(); string fullPath = path + fileName; //调试时,便于观察,而做的输出 Console.WriteLine(fullPath); FileFather ff = GetFile(fullPath); ff.OpenFile(); Console.ReadKey(); }
public static FileFather GetFile(string fullPath) { string extension = Path.GetExtension(fullPath); //调试时,便于观察,而做的输出 Console.WriteLine(extension); FileFather ff = null; switch (extension) { //切记Path.GetExtension(fullPath);返回的的文件后缀是带有一个点的 case ".txt": ff = new TxtFile(fullPath); break; case ".jpg": ff = new jpgFile(fullPath); break; case ".wav": ff = new wavFile(fullPath); break; } return(ff); }