static void Main(string[] args) { Console.WriteLine("请输入要进入的磁盘:"); string path = Console.ReadLine(); Console.WriteLine("请输入一个文件名:"); string fileName = Console.ReadLine(); FileFather ff = GetFile(fileName, path + fileName); ff.OpenFile(); }
public static FileFather GetFile(string fileName, string fullPath) { FileFather ff = null; string extension = Path.GetExtension(fileName); switch (extension) { case ".txt": ff = new TxtFile(fullPath); break; case ".jpg": ff = new JpgFile(fullPath); break; case ".flv": ff = new FlvFile(fullPath); break; } return(ff); }