zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    重回大一
    20071027我以为我很大度
    凌晨三点
    山洞爱情
    JQuery上传插件Uploadify使用详解
    jquery ui layout
    win2003下direct的问题
    Aptana一些快键用法
    IE、Firefox、Chrome 的JS代码兼容注意事项
    2011学习计划
  • 原文地址:https://www.cnblogs.com/chao202426/p/9241422.html
Copyright © 2011-2022 走看看