'File.Copy'不会覆盖文件 [英] 'File.Copy' does not overwrite a file
本文介绍了'File.Copy'不会覆盖文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用以下代码,我试图覆盖文件(如果存在)。目前,它抛出 IOException 。如何解决此问题?
File.Copy(filePath,newPath);
解决方案
使用
File.Copy(filePath,newPath,true);
第三个参数将被覆盖,因此如果将其设置为true,则目标文件将被覆盖。 / p>
请参阅: File.Copy在MSDN中
Using the following code, I am trying to overwrite a file if it exists. Currenly it throws IOException. How can I fix this problem?
File.Copy(filePath, newPath);
解决方案
Use
File.Copy(filePath, newPath, true);
The third parameter is overwrite, so if you set it to true the destination file will be overwritten.
这篇关于'File.Copy'不会覆盖文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文