该文件已存在时无法创建该文件 [英] Cannot create a file when that file already exists

查看:284
本文介绍了该文件已存在时无法创建该文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Winforms,并且试图将文件从一个位置复制到另一个位置.如果已经有一个同名文件,我要覆盖它.但是我收到类似该文件已存在时无法创建文件"之类的错误.

I am using Winforms, and I am trying to copy a file from one location to another. If a file with the same name is already there, I want to overwrite it. But I get an error like "Cannot create a file when that file already exists."

我要覆盖文件.我该怎么办? 我尝试使用File.copy而不是File.move,但是出现了相同的错误.

I want to overwrite the file. What should I do? I tried File.copy instead of File.move, but I got the same error.

推荐答案

File.Copy(source,destination,true)将覆盖目标.请参见文档.

File.Copy(source,destination,true) will overwrite destination if permissions allow. See the docs.

这篇关于该文件已存在时无法创建该文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆