Creating an empty file in C#

前端 未结 7 526
渐次进展
渐次进展 2020-12-02 07:13

What\'s the simplest/canonical way to create an empty file in C#/.NET?

The simplest way I could find so far is:

System.IO.File.WriteAllLines(filename         


        
7条回答
  •  青春惊慌失措
    2020-12-02 07:31

    System.IO.File.Create(@"C:\Temp.txt");
    

    As others have pointed out, you should dispose of this object or wrap it in an empty using statement.

    using (System.IO.File.Create(@"C:\Temp.txt"));
    

提交回复
热议问题