StreamWriter StreamReader
private void WriteLoginJsonData(object jsonData) { using (FileStream writerFileStream = new FileStream(JsonDataFile, FileMode.OpenOrCreate)) { using (StreamWriter writerStream = new StreamWriter(writerFileStream, Encoding.UTF8)) { writerFileStream.SetLength(0); string loginDataJson = JsonConvert.SerializeObject(jsonData, Formatting.Indented); writerStream.WriteLine(loginDataJson); writerStream.Close(); } writerFileStream.Close(); } }
private void ReadLoginJsonData() { if (File.Exists(JsonDataFile)) { using (FileStream readerFileStream = new FileStream(JsonDataFile, FileMode.Open, FileAccess.Read)) { using (StreamReader readerStream = new StreamReader(readerFileStream, Encoding.UTF8)) { string jsonContent= readerStream.ReadToEnd(); if (!string.IsNullOrWhiteSpace(jsonContent)) { Console.WriteLine(jsonContent); } readerStream.Close(); } readerFileStream.Close(); } } }