文本文件的读取

对于文本文件不需要转化为二进制文件

 

    class Demo3
    {
        private string _strPath = @"D:\Test.txt";

        public void Test1()
        {
            StreamWriter sw = new StreamWriter(_strPath);
            string str = "我不是英雄,我只是拿锤子的越大人!";
            sw.WriteLine(str);
            sw.Close();
        }

        public void Test2()
        {
            StreamReader sr = new StreamReader(_strPath);
            while (sr.Peek()>=0)
            {
                Console.WriteLine(sr.ReadLine());
            }
            sr.Close();
        }

        static void Main(string[] args)
        {
            Demo3 obj = new Demo3();
            obj.Test2();
        }

    }

 

其中StreamReader和StreamWriter数据流进行实现,整体上较为简洁。

 

posted @ 2019-02-27 21:22  彩色的梦  阅读(214)  评论(0编辑  收藏  举报