我想做如下的事情。什么函数返回一个打开的唯一文件?所以我可以确保它是我的,我不会覆盖任何东西或编写复杂的 fn 生成/循环
BinaryWriter w = GetTempFile(out fn);
w.close();
File.Move(fn, newFn);
最佳答案
有两种方法:
-
这将创建一个临时文件并返回其名称。
-
这将使用加密强度高的随机字符串作为文件名,并且不会为您创建文件。
通常第一种方法就足够了; GetRandomFileName 的文档说:
When the security of your file system is paramount, this method should be used instead of GetTempFileName.
关于c# - 在 .NET 中获取/打开临时文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2741306/