天天看點

C#程式設計-22:判斷檔案是否存在并建立檔案(夾)

string path = @"D:\abc";

string fileName = "123.txt";

if (!Directory.Exists(path))

{

   Directory.CreateDirectory(path);

}

if (!File.Exists(path + "\\" + fileName))

   File.Create(path + "\\" + fileName);