首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >正在复制文件,文件未处理

正在复制文件,文件未处理
EN

Stack Overflow用户
提问于 2012-09-27 17:47:57
回答 2查看 140关注 0票数 0

我有以下复制文件的代码:

代码语言:javascript
复制
var copedFile = ConfigurationManager.AppSettings["PathToFirebirdDB"] + ".001";

using (var inputFile = new FileStream( ConfigurationManager.AppSettings["PathToFirebirdDB"],
        FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
{
    using (var outputFile = new FileStream(copedFile, FileMode.Create))
    {
        var buffer = new byte[0x10000];
        int bytes;

        while ((bytes = inputFile.Read(buffer, 0, buffer.Length)) > 0)
        {
            outputFile.Write(buffer, 0, bytes);
        }
    }
}

这段代码只工作一次。下次我收到下面的消息时:

代码语言:javascript
复制
 The process cannot access the file 'D:\Programs\IBExpert\db.fdb.001' because it is being used by another process. System.IO.IOException: The process cannot access the file 'D:\Programs\IBExpert\db.fdb.001' because it is being used by another process.

为什么?有using块。

EN

回答 2

Stack Overflow用户

发布于 2012-09-27 18:01:17

如果您在关闭文件后尝试重新打开该文件,则系统仍有可能认为该文件处于打开状态,因为它实际上是打开的。

一个典型的原因是病毒扫描程序保持文件打开以确保它没有被感染,这在后台发生,并可能在您自己关闭文件后继续运行。

票数 1
EN

Stack Overflow用户

发布于 2012-09-27 17:52:18

可能是因为您没有关闭这些文件。

顺便说一句,为什么不直接使用File.Copy呢?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12618559

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档