• c#基础学习(0628)之使用进程打开指定的文件、模拟磁盘打开文件


    使用进程打开指定的文件
    View Code

    模拟磁盘打开文件

    class Program
    {
      static void Main(string[] args)
      {
        while(true)
        {    
        Console.WriteLine("请选择要进入的磁盘");
        string path=Console.ReadLine();//D:
        Console.WriteLine("请选择要打开的文件");
        string fileName=Console.ReadLine();//1.txt
        //文件的全路径: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;
      }
    }
    public abstract class FileFather
    {
      public string fullPath
      {
        get;
        set;
      }
      public FileFather(string fullPath)
      {
        this.fullPath=fullPath;
      }
      public abstract void OpenFile();
    }
    public class TxtPath:FileFather
    {
      public TxtPath(string fullPath):base(fullPath)
      {
        
      }
      public override void OpenFile()
      {
        ProcessStartInfo psi=new ProcessStartInfo(this.fileName);
        Process p=new Process();
        p.StartInfo=psi;
        p.Start();
      }
    }
    public class JpgPath:FileFather
    {
      public JpgPath(string fullPath):base(fullPath)
      {
        
      }
      public override void OpenFile()
      {
        ProcessStartInfo psi=new ProcessStartInfo(this.fileName);
        Process p=new Process();
        p.StartInfo=psi;
        p.Start();
      }
    }
    public class WmvPath:FileFather
    {
      public WmvPath(string fullPath):base(fullPath)
      {
        
      }
      public override void OpenFile()
      {
        ProcessStartInfo psi=new ProcessStartInfo(this.fileName);
        Process p=new Process();
        p.StartInfo=psi;
        p.Start();
      }
    }
        
    View Code
  • 相关阅读:
    第三章 套接字编程简介
    Effective STL 学习关于容器
    C++单例模板
    第六章 IO复用:select和poll函数
    第五章 TCP客户服务器程序示例
    八、基本UDP套接字编程
    第四章 基本TCP套接字编程
    测试 LaTeX
    如何在不支持 LaTeX 的环境使用 LaTeX 命令输入公式?
    Ubuntu 下 Wine 安装微软 Office
  • 原文地址:https://www.cnblogs.com/chao202426/p/9241422.html
Copyright © 2020-2023  润新知