有没有办法在c#解决方案的临时目录中包含临时文件并将字节写入该文件,并在完成我们的流程后删除它而不向用户显示该文件?
答案 0 :(得分:2)
考虑使用
string tempFile = Path.GetTempFileName();
//Use the file
File.Delete(tempFile);
答案 1 :(得分:1)
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);
}
}