vb.net FileIO.FileSystem.CopyFile() 与 System.IO.File.Copy()

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14212080/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 11:49:21  来源:igfitidea点击:

FileIO.FileSystem.CopyFile() vs System.IO.File.Copy()

.netvb.netcopy

提问by Dave

I have a couple of questions about the difference between this 2 classes and these specific methods, FileIO.FileSystem.CopyFile() and System.IO.File.Copy()

我有几个关于这 2 个类和这些特定方法 FileIO.FileSystem.CopyFile() 和 System.IO.File.Copy() 之间的区别的问题

At the simplest level, they both do the same thing when overloaded with sourceFile, destinationFile and bool set to true to overwrite. EG

在最简单的层面上,当 sourceFile、destinationFile 和 bool 设置为 true 以覆盖时,它们都会做同样的事情。例如

FileIO.FileSystem.CopyFile(source, destination, True) 
System.IO.File.Copy(source, destination, True)

My two questions are

我的两个问题是

  1. What are the differences between the 2 with the overload shown because I can't find (or may be I missed the point) anything on the MSDN site.
  2. How do you (the kind person answering) know the differences when it isn't in the MSDN documentation?
  1. 由于我在 MSDN 站点上找不到(或者我可能错过了重点)任何内容,因此显示的重载 2 之间有什么区别。
  2. 当 MSDN 文档中没有时,您(回答的好心人)如何知道差异?

采纳答案by Antonio Bakula

VisualBasic version after some checks calls System.IO.File.Copy, and I find that out by using the dotPeek, dotPeek is .NET decompiler.

经过一些检查后的 VisualBasic 版本调用 System.IO.File.Copy,我通过使用 dotPeek 发现,dotPeek 是 .NET 反编译器。

回答by PaulB

A quick look at Microsoft.VisualBasic.dllin reflector shows FileIO.FileSystem.Copydoes just hand over to File.Copyafter doing a couple of sanity checks (file, directory exists for example) and creating the destination directory if needed.

在反射器显示中快速查看Microsoft.VisualBasic.dllFileIO.FileSystem.Copy只是File.Copy在执行一些完整性检查(例如文件、目录存在)并根据需要创建目标目录后才移交给。

回答by Martin Milan

The only difference I can see is that they have potential to raise a different list of exceptions - and I discovered that, I'm afraid, by reading the MSDN documentation :o)

我能看到的唯一区别是他们有可能提出不同的例外列表 - 我担心,通过阅读 MSDN 文档,我发现了这一点 :o)

回答by Dave

After my own research, it does appear to do something not documented.

经过我自己的研究,它似乎确实做了一些没有记录的事情。

FileIO.FileSystem.CopyFile(source, destination, true)will create a folder if it doesn't exist, where as System.IO.File.Copy(source, desintation, true)doesn't and throws an exception.

FileIO.FileSystem.CopyFile(source, destination, true)如果文件夹不存在,将创建一个文件夹,如果不存在System.IO.File.Copy(source, desintation, true)并抛出异常。

It also appearsthat when using FileIO.FileSystem.CopyFile(source, destination, true)the reference remains in memory, so when trying to delete the new folder or file, an exception is thrown "...already in use by another process".

它也出现在使用时FileIO.FileSystem.CopyFile(source, destination, true)在内存中的引用保持,因此试图删除新的文件夹或文件时,会抛出异常“ ......已被另一程序使用”。