SLa*_*aks 162
File.WriteAllText(path, String.Empty);
Run Code Online (Sandbox Code Playgroud)
或者,
File.Create(path).Close();
Run Code Online (Sandbox Code Playgroud)
Dea*_*ing 17
只需使用FileMode.Truncate标志打开文件,然后关闭它:
using (var fs = new FileStream(@"C:\path\to\file", FileMode.Truncate))
{
}
Run Code Online (Sandbox Code Playgroud)
using (FileStream fs = File.Create(path))
{
}
Run Code Online (Sandbox Code Playgroud)
将创建或覆盖文件.