这两种移动文件的方法有什么区别吗?
System.IO.FileInfo f = new System.IO.FileInfo(@"c:\foo.txt");
f.MoveTo(@"c:\bar.txt");
//vs
System.IO.File.Move(@"c:\foo.txt", @"c:\bar.txt");
最佳答案
查看此 MSDN 页面中的“备注”部分 http://msdn.microsoft.com/en-us/library/akth6b1k.aspx :
If you are going to reuse an object several times, consider using the instance method of
FileInfo
instead of the corresponding static methods of theFile
class, because a security check will not always be necessary.
我认为这种差异在 File
(Directory
) 和 FileInfo
(DirectoryInfo
) 类之间最为明显。
更新:类似问题的相同解释:https://stackoverflow.com/a/1324808/380123
关于c# - FileInfo.MoveTo() 与 File.Move(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2733288/