我愿做这样的事情的下文。什么函数返回我打开了一个独特的文件?这样我就可以确保它是我的,我不会覆盖任何内容或编写复杂的FN生成/循环
的BinaryWriter W = GetTempFile(出FN); w.close(); File.Move(FN,newFn);解决方案
有两种方法如下:
-
Path.GetTempFileName
这将创建一个临时文件,并返回其名称。
-
Path.GetRandomFileName
这将使用保密性强的随机字符串作为文件名,并不会为你的文件。
通常第一种方法就足够了;对于GetRandomFileName该文件说:
当你的文件系统的安全性是最重要的,应该用来代替GetTempFileName这种方法。
I would like to do something like the below. What function returns me an unique file that is opened? so i can ensure it is mine and i wont overwrite anything or write a complex fn generate/loop
BinaryWriter w = GetTempFile(out fn); w.close(); File.Move(fn, newFn);解决方案
There are two methods for this:
Path.GetTempFileName
This will create a temporary file and return its name.
Path.GetRandomFileName
This will use a cryptographically strong, random string as file name and won't create the file for you.
Usually the first method suffices; the documentation for GetRandomFileName says:
When the security of your file system is paramount, this method should be used instead of GetTempFileName.
更多推荐
获取.NET /打开临时文件
发布评论