C# 讀寫txt

//表示清空 txt
StreamWriter sw = new StreamWriter("D:\\1.txt");
            string w = "";
            sw.Write(w);
            sw.Close();
//表示向txt寫入文本
StreamWriter sw = new StreamWriter("D:\\1.txt");
            string w = "10";
            sw.Write(w);
            sw.Close();
//表示追加文本
 StreamWriter sw =File.AppendText("D:\\1.txt");
            string w = "2";
            sw.Write(w);
            sw.Close();

//讀取文本this

   StreamReader sr = new StreamReader(Application.StartupPath +"\\txtreader.txt", false);             str = sr.ReadLine().ToString();             sr.Close();             this.textBox1.Text = str;///讀取
相關文章
相關標籤/搜索