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++)
{
sw.WriteLine(this.歷史記錄List[i]);
}
sw.Close();
sw.Dispose();
{
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++)
{
sw.WriteLine(this.歷史記錄List[i]);
}
sw.Close();
sw.Dispose();
}
}
}
private List
{
try
{
List
using (System.IO.StreamReader sr = new System.IO.StreamReader("CFile.a"))
{
String line;
while ((line = sr.ReadLine()) != null)
{
data.Add(line);
}
sr.Close();
sr.Dispose();
}
return data;
}
catch
{
return null;
}
}
#寫入檔案,保留之前資料,持續寫入 方法1
private void 文件記錄(string 記錄內容, string 檔案名稱,string 檔案位置)
{
System.IO.DirectoryInfo logDirection = new System.IO.DirectoryInfo(檔案位置);
System.IO.FileInfo logFile = new System.IO.FileInfo(檔案位置+ "\\" + 檔案名稱);
System.IO.StreamWriter Log;
{
System.IO.DirectoryInfo logDirection = new System.IO.DirectoryInfo(檔案位置);
System.IO.FileInfo logFile = new System.IO.FileInfo(檔案位置+ "\\" + 檔案名稱);
System.IO.StreamWriter Log;
if (logDirection.Exists == false)
logDirection.Create();
Log = logFile.AppendText();
Log.WriteLine(記錄內容);
Log.Flush();
Log.Close();
Log.Dispose();
Log = null;
}
#寫入檔案,保留之前資料,持續寫入 方法2
File.AppendAllText(檔名, 內容);
留言
張貼留言