开发者

Temp file inside project solution?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜