您的位置:首页 > 编程语言 > C#

C# 操作记事本文本

2017-11-23 16:26 225 查看
        protected void PublicAction(string slowStr)//slowStr就是你想写入的文本

        {

            FileStream fs = new FileStream(@"F:\log.txt", FileMode.OpenOrCreate, FileAccess.Write);

            StreamWriter sw = new StreamWriter(fs);

            sw.BaseStream.Seek(0, SeekOrigin.End);

            sw.WriteLine("WindowsService: " + slowStr + "  " + DateTime.Now.ToString() + "\n\n");//写入文本

            sw.Flush();

            sw.Close();

            fs.Close();

        }
public stringPublicActionRead(string path)

        {
            StreamReader sr = new StreamReader(path, Encoding.Default);

            String str;

            while ((str= sr.ReadLine()) != null)

            {

                str+=str;

            }
return str;//str就是读取出来的所有文本

        }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: