20070709 14:51:19 AppDBScoutManager.LogScan|ex=System.IO.IOException: The process cannot access the file "D:\Log\BS\BS20070709.log" because it is being used by another process.
   at System.IO.__Error.WinIOError(Int32 errorCode, String str)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean useAsync, String msgPath, Boolean bFromProxy)
   at System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path, Encoding encoding, Boolean detectEncodingFromByteOrderMarks, Int32 bufferSize)
   at System.IO.StreamReader..ctor(String path)
   at Megajoy.Vod.Tool.Scount.BSDBScoutModule.AppLog.FindErrorInLog(String LastCheckFileName, Int32 BeginLine, String BeginTime, Int32& ErrorLine, String& ErrorTime, String& CheckLogFileName, String& ErrMsg) in d:\project\vod_src\interface\bsdbscout\src\bsdbscoutmodule\applog.cs:line 65这个是报的错误。我不知道怎么处理?高手帮忙一下我这个菜鸟

解决方案 »

  1.   

    如果文件在读取中,应该是无法打开的(就算是拷贝文件都不行)。如果文件被读取完毕,读取权限就会被释放,这时候就可以被另一个程序打开。最简单的例子,就是MsSql的数据库文件,当Sql Server运行的时候,你甚至无法拷贝活动的数据库文件的。
      

  2.   

    我已经解决了。谢谢各位朋友。解决方法:File.Copy( CheckFile, strTempDestFilePath, true ); 
    FileStream logFieStream = new FileStream( strTempDestFilePath, FileMode.Open, FileAccess.Read );
    StreamReader vLogStreamReader = new StreamReader( logFieStream, System.Text.Encoding.Default );