C# 操作記事本文本

        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就是讀取出來的所有文本
        }

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章