在C#.net中如何同时读写一个文件
uxeir 2005-06-11 01:52:08 我现在有两个程序A和B,
程序A会象写日志一样不停向一个文件中写入数据,代码如下:
fsw=new FileStream(@"C:\temp\xxx.log",System.IO.FileMode.Create,System.IO.FileAccess.Write);
希望程序B能随时访问A写的xxx.log文件,代码如下:
fsr=new FileStream(@"C:\temp\xxx.log",System.IO.FileMode.Open,System.IO.FileAccess.Read);
但是在程序B运行时提示:
未处理的“System.IO.IOException”类型的异常出现在 mscorlib.dll 中。
其他信息: 该进程无法访问文件“C:\temp\xxx.log”,因为该文件正由另一进程使用。
而在程序A写入的过程中,用记事本可以打开C:\temp\xxx.log,说明文件是可访问,我的程序B的读法有什么不对的地方嘛?望高手指点。。。