在线等,编译C#版飞鸽传书出现的问题

nakoka 2009-11-19 04:20:08
用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();
}

}
}
...全文
214 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
ksig188 2010-04-16
  • 打赏
  • 举报
回复
4楼的话没有明白,具体怎么弄?我也遇到这个问题了……
________hi 2009-12-12
  • 打赏
  • 举报
回复
dreamsnake 2009-11-20
  • 打赏
  • 举报
回复
UserInformation 被锁定了。

看你的代码,Try Catch 部分。如果在 Try 的时候,文件被打开,然后关闭前出错,你的处理是在 Catch 里重新打开它?所以,你这个文件被锁定了。
nakoka 2009-11-19
  • 打赏
  • 举报
回复
求高手解答~~
cymandhxl 2009-11-19
  • 打赏
  • 举报
回复
[b]楼上的签名好像很好呢。[/b]
cc_net 2009-11-19
  • 打赏
  • 举报
回复
C#版飞鸽传书??

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧