Creating an empty file in C#

前端 未结 7 506
渐次进展
渐次进展 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:46

    Path.GetTempFileName() will create a uniquly named empty file and return the path to it.

    If you want to control the path but get a random file name you can use GetRandomFileName to just return a file name string and use it with Create

    For example:

    string fileName=Path.GetRandomFileName();
    File.Create("custom\\path\\" + fileName);
    
    0 讨论(0)
提交回复
热议问题