gpt4 book ai didi

c# - FileInfo.MoveTo() 与 File.Move()

转载 作者:IT王子 更新时间:2023-10-29 04:23:28 24 4
gpt4 key购买 nike

这两种移动文件的方法有什么区别吗?

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 the File 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com