每次進入軟體都執行一次,每次都會保存一個數,如何僅執行一次,更改的時候還能把原來的資料清理掉
private void textBox1_TextChanged(object sender, EventArgs e)
{
System.IO.File.AppendAllText("C:\\Users\\Lamic\\Desktop\\資料記錄.txt", textBox1.Text+ "\r\n");
}
private void MainInterface_Load(object sender, EventArgs e)
{
textBox1.Text = System.IO.File.ReadAllText("C:\\Users\\Lamic\\Desktop\\資料記錄.txt");
}
uj5u.com熱心網友回復:
改成System.IO.File.CreateText就好了uj5u.com熱心網友回復:

改了以后,直接就拋出例外了
uj5u.com熱心網友回復:
using (StreamWriter sw = File.CreateText("test.txt"))
{
sw.WriteLine("Hello");
sw.WriteLine("World");
}
uj5u.com熱心網友回復:
用ini或sqlite把至少你不用擔心占用,多執行緒,例外掉電資料例外等問題
像上面說重新生成檔案的瞬間掉電,下次進來就是0位元組檔案了
uj5u.com熱心網友回復:
改成System.IO.File.WriteAllText轉載請註明出處,本文鏈接:https://www.uj5u.com/net/269488.html
標籤:C#
