static void Main(string[] args) { while (true) { Console.WriteLine("请选择要进入的磁盘"); string path = Console.ReadLine(); Console.WriteLine("请选择要打开的文件"); string fileName = Console.ReadLine(); //文件的全路径:path+fileName FileFather ff = GetFile(fileName, path + fileName); ff.OpenFile(); Console.ReadKey(); } }
public static FileFather GetFile(string fileName, string fullPath) { string extension = Path.GetExtension(fileName); FileFather ff = null; switch (extension) { case ".txt": ff = new TxtPath(fullPath); break; case ".jpg": ff = new JpgPath(fullPath); break; case ".wmv": ff = new WmvPath(fullPath); break; } return(ff); }