获取.NET /打开临时文件 [英] Get/open temp file in .NET
问题描述
我愿做这样的事情的下文。什么函数返回我打开了一个独特的文件?这样我就可以确保它是我的,我不会覆盖任何内容或编写复杂的FN生成/循环
的BinaryWriter W = GetTempFile(出FN);
w.close();
File.Move(FN,newFn);
有两种方法如下:
-
<一个href="http://msdn.microsoft.com/en-us/library/system.io.path.gettempfilename%28v=VS.100%29.aspx">Path.GetTempFileName
这将创建一个临时文件,并返回其名称。
-
<一个href="http://msdn.microsoft.com/en-us/library/system.io.path.getrandomfilename%28v=VS.100%29.aspx">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:
-
This will create a temporary file and return its name.
-
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 /打开临时文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!