C#判断文件存在的几种方法详解

  C#判断文件存在需要从几方面入手,这里介绍的三种方法,主要是实现硬盘上的判断。判断文件存在,是进行文件操作的基础。
  命名空间:System.IO
  C#判断文件存在第一种方法:
  File.Exists(Application.StartupPath + "\\AlarmSet.txt");
  C#判断文件存在第二种方法:
  System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(Application.StartupPath + "\\AlarmSet.txt");
  MessageBox.Show(info.Exists.ToString());
  C#判断文件存在第三种方法:
  File.Create(Application.StartupPath + "\\AlarmSet.txt");//创建该文件

你可能感兴趣的:(C#,判断文件存在)