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

C#判断文件存在需要从几方面入手,这里介绍的三种方法,主要是实现硬盘上的判断。判断文件存在,是进行文件操作的基础。

命名空间:System.IO

C#判断文件存在***种方法:

 
 
 
  1. File.Exists(Application.StartupPath + "\\AlarmSet.txt"); 

C#判断文件存在第二种方法:

 
 
 
  1. System.IO.DirectoryInfo info = new System.IO.DirectoryInfo(Application.StartupPath + "\\AlarmSet.txt");  
  2. MessageBox.Show(info.Exists.ToString()); 

C#判断文件存在第三种方法:

 
 
 
  1. File.Create(Application.StartupPath + "\\AlarmSet.txt");//创建该文件 

【编辑推荐】

  1. C#截取字符串函数实例解析
  2. C#截取字符串实际应用浅析
  3. C#截取字符串实战操作解析
  4. 浅析C#工作流以及功能
  5. C#工作流引擎的理解解析
THE END