更新时间:2023-11-27 16:01:52
您可以判断是否存在指定的文件中使用的存在
方法文件
类中的 System.IO
命名空间:
You can determine whether a specified file exists using the Exists
method of the File
class in the System.IO
namespace:
bool System.IO.File.Exists(string path)
您可以在这里找到文档在MSDN上。
示例:
using System;
using System.IO;
class Test
{
public static void Main()
{
string resumeFile = @"c:\ResumesArchive\923823.txt";
string newFile = @"c:\ResumesImport\newResume.txt";
if (File.Exists(resumeFile))
{
File.Copy(resumeFile, newFile);
}
else
{
Console.WriteLine("Resume file does not exist.");
}
}
}