我用下面的程序来新建一个b.txt,然后用StreamReader来读取里面的数值,可是当执行到StreamReader那一行时就跳出来,说另一个进程正在使用该文件,我该怎样处理呢?
FileInfo file1=new FileInfo(@"f:\b.txt");
if(!file1.Exists)
{
file1.Create();
}
StreamReader read=new StreamReader(@"f:\b.txt",System.Text.Encoding.Default);
string strText=read.ReadToEnd();
read.Close();
string [] ss=strText.Split('\n');
string s=ss[ss.Length-2];
string [] d=s.Split(' ');
this.textBox1.Text=d[0];
this.textBox2.Text=d[1];
this.textBox3.Text=d[2];
FileInfo file1=new FileInfo(@"f:\b.txt");
if(!file1.Exists)
{
file1.Create();
}
StreamReader read=new StreamReader(@"f:\b.txt",System.Text.Encoding.Default);
string strText=read.ReadToEnd();
read.Close();
string [] ss=strText.Split('\n');
string s=ss[ss.Length-2];
string [] d=s.Split(' ');
this.textBox1.Text=d[0];
this.textBox2.Text=d[1];
this.textBox3.Text=d[2];
{ file1.Create().Close();
}