C# 讀檔和寫檔 範例1
public List 歷史記錄List = new List();
private void 寫檔()
{
int i;
this.歷史記錄List.Add(System.DateTime.Now.ToString() + "**" +時間計時.Text );
//寫入資料
using (System.IO.StreamWriter sw = new System.IO.StreamWriter("CFile.a"))
{
for (i = 0; i < this.歷史記錄List.Count; i++)
{
// Add some text to the file.
sw.NewLine = this.歷史記錄List[i];
//sw.WriteLine(DateTime.Now);
//sw.Write("aaa\tbbb");
}
}
}
private void 讀檔()
{
try
{
using (System.IO.StreamReader sr = new System.IO.StreamReader("CFile.a"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
//Console.WriteLine(line);
this.歷史記錄List.Add(line);
}
}
}
catch
{
}
}
留言
張貼留言