Finishing file operations (c)

  Introducing Microsoft provided, File and FileInfo a complete description.

  I am currently just finishing their own method used. For example, to determine whether a file exists.  

 static void Main(string[] args)
        {
            string path = @"E:\testfile01.txt";

            bool flag = File.Exists(path);

            if (flag)
            {
                Console.WriteLine("文件存在");
            }
            else
            {
                Console.WriteLine("文件不存在");
            }

            Console.Read();
        }

  Microsoft's documentation page on the introduction of very detailed. When said path Exist method should not be used to verify, to check whether the directory exists, use Directory.Exists. File.Exists just check whether the specified file exists.

  Here is a FileInfo class, complete check whether the specified file exists.

 static void Main(string[] args)
        {

            string path = @"E:\testfile01.txt";

            FileInfo fInfo = new FileInfo(path);

            bool flag = fInfo.Exists;

            if (flag)
            {
                Console.WriteLine("文件存在");
            }
            else
            {
                Console.WriteLine("文件不存在");
            }

            Console.Read();
        }

  This is Microsoft's introduction , the FileInfo is a need to instantiate constructor string type, and is a property of an object Exists.

  Well, I have this problem at this time. Why have a static File class and FileInfo instance of class two, they all have the function of file operations.

  Now, do not tangle this problem. Two classes .net framework provided, to check whether a file exists, I would.

Guess you like

Origin www.cnblogs.com/158-186/p/10939532.html
Recommended