zoukankan      html  css  js  c++  java
  • 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();
                    }
                }
            }
  • 相关阅读:
    MYSQL
    spider
    git命令
    just_connect.py
    3sql
    4sql
    2sql
    springMVC3学习(六)--SimpleFormController
    springMVC3学习(五)--MultiActionController
    springMVC3学习(四)--访问静态文件如js,jpg,css
  • 原文地址:https://www.cnblogs.com/Fred1987/p/11660385.html
Copyright © 2011-2022 走看看