在C#中判断文件是否存在用Exists,这个方法声明如下: 

判断指定文件path 是否存在,如果存在返回true,否则返回false

public  static bool Exists (String Path)

#region 判断文件是否存在
            const string path = @"C:\oscar.txt";
               using (FileStream fs = File.Create(path))
               {
               using(StreamWriter sw = new StreamWriter (fs))
               {
                 sw.WriteLine("oscar wenjian");
               }
               }
           
            if (File.Exists(path))
            {
                Console.WriteLine("文件已存在");
                               }
            }
            else
            {
                Console.WriteLine("文件不存在");
            }
            #endregion

Posted on 2010-12-30 16:23  lichen396116416  阅读(548)  评论(0编辑  收藏  举报