private void addUser(string username,string password,int teaOrstu)
{
Users newUser = new Users(username, password);
if (teaOrstu == 0)//判断身份,如果是学生
{
//静态变量中添加新用户
StaticUsers.usersStu.Add(newUser);
//用户文本中写入新用户
string[] readTxt = File.ReadAllLines(stuUserPath);//读取教师用户文本
if (readTxt.Length == 0)//判断用户文本是否为空
{
string[] firstUserStu = new string[] { username, password };
File.WriteAllLines(stuUserPath, firstUserStu); //第一行写入用户名,第二行写入密码
}
else
{
readTxt[0] += "," + username;
readTxt[1] += "," + password;
File.WriteAllLines(stuUserPath, readTxt);
}
//创建用户详情记录文本
string userInfoFile = stuInfoPath + username + ".txt";
File.Create(userInfoFile).Dispose(); //释放内存,否则文件会被一直占用
}
else
{
//静态变量中添加新用户
StaticUsers.usersTea.Add(newUser);
//用户文本中写入新用户
string[] readTxt = File.ReadAllLines(teaUserPath);//读取教师用户文本
if (readTxt.Length == 0)//判断用户文本是否为空
{
string[] firstUserTea = new string[] { username, password };
File.WriteAllLines(teaUserPath, firstUserTea); //第一行写入用户名,第二行写入密码
}
else
{
readTxt[0] += "," + username;
readTxt[1] += "," + password;
File.WriteAllLines(teaUserPath, readTxt);
}
//创建用户详情记录文本
string userInfoFile = teaInfoPath + username + ".txt";
File.Create(userInfoFile).Dispose(); //释放内存,否则文件会被一直占用
}
}
目录路径不存在,题主确认下
应该是123.txt这个文件不存在,所以导致的报错。