【发布时间】:2012-06-23 11:24:19
【问题描述】:
我目前正在复制 oracle server 的存档文件,我正在阻止发生的情况是,当我复制文件服务器时,它会在尝试更新文件时出错。
一开始我试过
File.Copy(source, Destination, true);
但似乎这种方法正在锁定文件,服务器在日志中抛出错误:
OSD-04002: unable to open file
O/S-Error: (OS 32) The process cannot access the file because it is being used by another process.
我把方法改成
FileStream rStream = new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
但是当我尝试使用带有 FileShare 的测试程序打开文件时。现在它也抛出一个错误,另一个进程正在锁定文件。
一旦另一个进程想要访问/写入文件,是否可以放手或释放文件?
【问题讨论】:
标签: c# file copy readonly fileshare