VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > temp > 简明python教程 >
  • 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();
                }
            }
        }
复制代码


相关教程