vs对文本的检测和读取

class MyIOManager
    {


        private string m_strDataPath = "D:\\MyGameNameAndScannerIDData.txt";


        private StreamReader m_StreamReader = null;


        private StreamWriter m_StreamWriter = null;


        private string m_strLineCache = "";


        /// <summary>
        /// 将要读取的文本文档是否存在
        /// </summary>
        /// <returns></returns>
        public bool MyExistsTxt()
        {
            if (File.Exists(m_strDataPath))
            {
                return true;
            }
            else
            {
                return false;
            }
        }


        /// <summary>
        /// 创建文本文档
        /// </summary>
        public void MyCreateTxt()
        {
           
                FileStream fs = new FileStream(m_strDataPath, FileMode.Create);
                fs.Close();
            


        }
       
        /// <summary>
        /// 读取数据
        /// </summary>
        public string MyReaderTxt()
        {


            m_StreamReader = new StreamReader(m_strDataPath);
            m_strLineCache = m_StreamReader.ReadLine();
            m_StreamReader.Dispose();
            m_StreamReader.Close();
            //Console.WriteLine(m_strLineCache);
            return m_strLineCache;
        }


        /// <summary>
        /// 存储数据
        /// </summary>
        /// <param name="_txt"></param>
        public void MyWriteTxt(string _txt)
        {
            m_StreamWriter = new StreamWriter(m_strDataPath,false);
            m_StreamWriter.WriteLine(_txt);
            m_StreamWriter.Flush();
            m_StreamWriter.Close();
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_39353597/article/details/78791435