小编use*_*649的帖子

如何清除文本文件内容c#

我希望使用此方法明确文本文件

private void writeTextFile(string filePath, string text)
{
    if (!File.Exists(filePath))
    {
        File.Create(filePath).Close();

    }
    using (StreamWriter tw = new StreamWriter(filePath))
    {
        File.WriteAllText(filePath,"");
        tw.WriteLine(text);
        tw.Close();
    }
}
Run Code Online (Sandbox Code Playgroud)

但我得到这个错误

The process cannot access the file  because it is being used by another process.
Run Code Online (Sandbox Code Playgroud)

但这不能在任何地方打开,

请帮我谢谢

c# streamwriter

4
推荐指数
1
解决办法
4万
查看次数

标签 统计

c# ×1

streamwriter ×1