using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace 模拟磁盘打开文件
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请选择要进入的磁盘");
string path = Console.ReadLine();
Console.WriteLine("请选择要打开的文件");
string fileName = Console.ReadLine();
FileFarher ff = GetFile(fileName,path+fileName);//返回的是被之类重写的FileFarher
ff.OpenFile();
Console.ReadLine();
}
public static FileFarher GetFile(string filename,string fullpath)
{
string extension = Path.GetExtension(filename);
FileFarher ff = null;
switch (extension)
{
case ".txt":ff = new TxTPath(fullpath);
break;
case ".jpg":ff = new JpgPath(fullpath);
break;
}
return ff;
}
}
public abstract class FileFarher //父类
{
public string fileName
{
get;
set;
}
public FileFarher(string filename)
{
this.fileName = filename;
}
public abstract void OpenFile();
}
public class TxTPath : FileFarher //继承父类
{ public TxTPath(string filename) : base(filename) //继承父类中的filename
{ }
public override void OpenFile()
{
ProcessStartInfo pso = new ProcessStartInfo(this.fileName);
Process p = new Process();
p.StartInfo = pso;
p.Start();
}
}
public class JpgPath : FileFarher //继承父类
{
public JpgPath(string filename) : base(filename) //继承父类中的filename
{ }
public override void OpenFile()
{ }
}
}

最新文章

  1. mysql xml 参数
  2. linux默认网关的设置
  3. What is /proc/slabinfo?
  4. 转:python webdriver API 之下拉框处理
  5. Topic Model
  6. 网络基础知识、ASP.NET 核心知识(1)*
  7. ListView中不同类型view的实现
  8. (入门篇 NettyNIO开发指南)第五章-分隔符和定长解码器使用
  9. java中计算两个时间差
  10. 数组的toString方法
  11. C# 中 realdonly不等于只读
  12. [Swift]LeetCode827. 最大人工岛 | Making A Large Island
  13. pyexecjs模块
  14. c++字节对齐
  15. 12. Integer to Roman (JAVA)
  16. saltstack自动化运维系列11基于etcd的saltstack的自动化扩容
  17. [BZOJ 1260][CQOI2007]涂色paint 题解(区间DP)
  18. perl 查看某个模块的安装路径
  19. 解决Error creating bean with name 'huayuanjingguanDaoimp' defined in file [D:\apache-tomcat-7.0.52\webapps\landscapings\WEB-INF\classes\com\itheima\landscaping\dao\imp\huayuanjingguanDaoimp.class]: Invo
  20. 小程序获取openid unionid session_key

热门文章

  1. CF585E. Present for Vitalik the Philatelist [容斥原理 !]
  2. 编写服务器程序时遇到的connect:no route to host的问题
  3. demo说明
  4. 阿里云学习之IOT物联网套件(配置篇)
  5. Maven文件配置
  6. POJ 1018 Communication System(贪心)
  7. SQL SERVER FOR LINUX初体验
  8. 使用Python管理数据库
  9. Java经典编程题50道之十五
  10. vue.js 安装过程(转载)