开发者

Temp file inside project solution?

开发者 https://www.devze.com 2023-03-09 02:40 出处:网络
Is t开发者_如何学编程here any way to have temp file inside a temp directory in c# solution and write the bytes into that and after finishing our process delete it without showing that file to users ?c

Is t开发者_如何学编程here any way to have temp file inside a temp directory in c# solution and write the bytes into that and after finishing our process delete it without showing that file to users ?


consider using

string tempFile = Path.GetTempFileName();
//Use the file
File.Delete(tempFile);


using System.IO;

class Logger
{
    static void Main()
    {
        // Create (and open) a new temporary file
        var filename = Path.GetTempFileName();
        var file = File.Open(filename, FileMode.Append);

        // Write bytes to it during the programs lifetime...
        file.Write(new byte[] { 1, 2, 3 }, 0, 3);

        // Just before closing your program, close and delete it
        file.Close();
        File.Delete(filename);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消