在线等,编译C#版飞鸽传书出现的问题
用VS2008.NET编译的时候出现以下提示:
文件“F:\飞鸽传书\FlyMessage\bin\Debug\UserInformation.txt”正由另一进程使用,因此该进程无法访问该文件。
即时窗口:
在 System.IndexOutOfRangeException 中第一次偶然出现的“FlyMessage.exe”类型的异常
在 System.IO.IOException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.IndexOutOfRangeException 中第一次偶然出现的“FlyMessage.exe”类型的异常
在 System.IO.IOException 中第一次偶然出现的“mscorlib.dll”类型的异常
在 System.IndexOutOfRangeException 中第一次偶然出现的“FlyMessage.exe”类型的异常
在 System.IO.IOException 中第一次偶然出现的“mscorlib.dll”类型的异常
部分代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
//CopyRight by TieXin
namespace FlyMessage
{
public partial class FrmSetUp : Form
{
public FrmSetUp()
{
InitializeComponent();
try
{
FileStream read = new FileStream(@"UserInformation.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(read);
string userInfo = sr.ReadLine();
string[] info = userInfo.Split(':');
this.txtUserName.Text = info[0];
this.txtWorkGroup.Text = info[1];
sr.Close();
read.Close();
}
catch
{
FileStream write = new FileStream(@"UserInformation.txt", FileMode.Create, FileAccess.Write);
string data = "";
StreamWriter sw = new StreamWriter(write);
sw.Write(data);
sw.Close();
write.Close();
}
}
private void btnConfirm_Click(object sender, EventArgs e)
{
if (this.txtUserName.Text == "" || this.txtWorkGroup.Text == "")
{
MessageBox.Show("请正确输入用户名和工作组!");
}
else
{
FileStream write = new FileStream(@"UserInformation.txt", FileMode.Create, FileAccess.Write);
string data =this.txtUserName.Text + ":" + this.txtWorkGroup.Text;
StreamWriter sw = new StreamWriter(write);
sw.Write(data);
sw.Close();
write.Close();
}
}
private void btnApp_Click(object sender, EventArgs e)
{
this.Update();
this.Close();
}
}
}