首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

原因是另一个进程正在使用该文件解决方法

2012-03-16 
原因是另一个进程正在使用该文件if (!File.Exists(\\ResidentFlash\\ReceiveData.txt)){File.Create(\\

原因是另一个进程正在使用该文件
if (!File.Exists("\\ResidentFlash\\ReceiveData.txt"))
{  
 File.Create("\\ResidentFlash\\ReceiveData.txt");
}
 using (StreamReader str = new StreamReader(@"\ResidentFlash\ReceiveData.txt"System.Text.Encoding.UTF8))//UTF8为编码


我创建完后对他进行读取...运行到using...那行代码就报错----“进程无法访问文“\ResidentFlash\ReceiveData.txt”,原因是另一个进程正在使用该文件”

求解决方法...

[解决办法]
这样操作文件
FileStream FileStream=null;
try
{
FileStream=new FileStream(@"\ResidentFlash\ReceiveData.txt",FileMode.Append)

using (StreamReader str = new StreamReader(@"\ResidentFlash\ReceiveData.txt"System.Text.Encoding.UTF8))//UTF8为编码
}
catch
{

}
finally 
{
str.Close(); 
FileStream.Close();
}

热点排行