在做文件拷贝/删除和移动之间的差异 [英] Difference between in doing file copy/delete and Move
问题描述
什么是
- 复制文件,并删除它使用
File.Copy()
和File.Delete()
李> - 使用移动文件
File.Move()
- Copying a file and deleting it using
File.Copy()
andFile.Delete()
- Moving the file using
File.Move()
在权限来执行这些操作所需的条件有什么区别?任何帮助非常AP preciated。
In terms of permission required to do these operations is there any difference? Any help much appreciated.
推荐答案
File.Move方法可用于从一个路径将文件移动到另一个。这种方法可以跨磁盘卷,并且它不会抛出异常,如果源和目标是相同的。
File.Move method can be used to move the file from one path to another. This method works across disk volumes, and it does not throw an exception if the source and destination are the same.
您不能使用Move方法来覆盖现有文件。如果试图通过将同名的文件到该目录中进行替换的文件,你会得到一个IOException异常。 为了克服这一点,你可以使用复制的组合和删除方法
You cannot use the Move method to overwrite an existing file. If you attempt to replace a file by moving a file of the same name into that directory, you get an IOException. To overcome this you can use the combination of Copy and Delete methods
这篇关于在做文件拷贝/删除和移动之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!