C#关于文件的创建

若使用文件夹Directory类判断了文件夹的存在,后面的文件就不需要使用File类来判断文件的存在与否和创建,只需要在前面判断过得文件夹路径后面加上文件的名字即可,它会自动判断文件是否存在,若不存在就创建。ps:个人目前的理解

public static void CreateFile(string appPath)

{

string fileName = @"Log\";
string path = Path.Combine(appPath, fileName);
if (!Directory.Exists(path))
{
DirectoryInfo directoryInfo = new DirectoryInfo(path);
directoryInfo.Create();

}
path = path + DateTime.Now.ToString("yyyyMMdd") + ".txt";

}

原文地址:https://www.cnblogs.com/sugarwxx/p/9922413.html