public void NicknameWrite(string Nickname) { var user = new Remember(); user.Nickname = Nickname; if (user != null) { using (FileStream fs = new FileStream("Remember.json", FileMode.Create)) { DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(Remember)); jsonFormatter.WriteObject(fs, user); } } else { using (FileStream fs = new FileStream("Remember.json", FileMode.Create)) { user = new Remember { Nickname = "" }; DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(Remember)); jsonFormatter.WriteObject(fs, user); } } }
public string NicknameRead() { var user = new Remember(); using (FileStream fs = new FileStream("NickInfo.json", FileMode.OpenOrCreate)) { DataContractJsonSerializer jsonFormatter = new DataContractJsonSerializer(typeof(Remember)); if (fs.Length != 0) { user = (Remember)jsonFormatter.ReadObject(fs); } } return(user.Nickname); }