A07_文本文件的读写

来源:互联网 发布:合金装备 mac 汉化 编辑:程序博客网 时间:2024/06/10 15:47

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.IO;namespace A07_IOTextFileReadAndWrite{    class Demo9    {        private string _StrPath = @"E:\test.txt";        //文本文件的写入        public void Test1()        {            string str = "Hello everyone!";            StreamWriter sw = new StreamWriter(_StrPath);            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)        {            Demo9 obj = new Demo9();            //obj.Test1();            obj.Test2();        }    }}