我在使用序列化将数据读取和写入文件记事本时遇到问题基本上是关于登录和注册我将在这里给出我的代码这是注册表单的部分:
public partial class formSignUp : Form
{
List<data> game = new List<data>();
data dt = new data();
public formSignUp()
{
InitializeComponent();
}
private void write()
{
try
{
using (Stream stream = File.OpenWrite("game.txt"))
{
BinaryFormatter bin = new BinaryFormatter();
bin.Serialize(stream, dt);
}
}
catch (IOException)
{
}
}
private void butRegister_Click(object sender, EventArgs e)
{
write();
dt = new data(tbUName.Text, tbPass1.Text);
game.Add(dt);
}
}
然后这是类数据代码:
[Serializable()]
class data
{
private string username;
private string password;
public string Username
{
get { return username; }
set { username = value; }
}
public string Password
{
get { return password; }
set { password = value; }
}
public data(string username, string password)
{
this.username = username;
this.password = password;
}
public data()
{
}
}
我将文件记事本放在名为“game.txt”的文件夹“bin”中
问题是,每次我调用“write()”时,写入文件“game.txt”的字符都是如此奇怪的字符。到目前为止,我喜欢:
ÿÿÿÿ <Login, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
Login.data 用户名密码
任何人都可以帮助我吗?非常感谢提前问候