寫入檔案>>
using System.IO;
StreamWriter sw = new StreamWriter(@"C:\text.txt", true);
//第二個參數設定為true表示不覆蓋原本的內容,把新內容直接添加進去
sw.WriteLine("寫入TXT的文字");
sw.Close();
讀取檔案>>
using System.IO;
StreamReader sr = new StreamReader(@"C:\text.txt");
//===一次讀取全部內容===
string a = sr.ReadToEnd();
Debug.Print(a);
//===逐行讀取,直到檔尾===
while (!sr.EndOfStream)
{
Debug.Print(sr.ReadLine());
}
sr.Close();
作者已經移除這則留言。
回覆刪除您好,我是剛學 C# 小白
回覆刪除請教,
Debug.Print(); =>黑視窗,無顯示資料
Debug.WriteLine();=>黑視窗,無顯示資料
Conlose.WriteLine();=>黑視窗,有顯示資料
差在哪呢? 都有黑視窗出現,但不見得有資料顯出?
感謝。
個人覺得 Debug 是開發者拿來看例外輸出用的(吧),Console 則是要輸出特定文字用的。如果你執行程式很成功那就沒有Debug 訊息只有Console 訊息...?
回覆刪除