protected void CreateFile()
{
String strTxt = ".\\" TEST.txt";
String strData = @"123456789";
// Delete a file by using File class static method...
if (System.IO.File.Exists(strTxt))
{
// Use a try block to catch IOExceptions, to
// handle the case of the file already being
// opened by another process.
try
{
System.IO.File.Delete(strTxt);
}
catch (System.IO.IOException e)
{
Console.WriteLine(e.Message);
return;
}
}
FileStream fileStream = new FileStream(strTxt, FileMode.Create);
fileStream.Close(); //切記開了要關,不然會被佔用而無法修改喔!!!
using (StreamWriter sw = new StreamWriter(strTxt,false))//覆寫檔案
{
// 欲寫入的文字資料 ~
sw.Write(strData );
//sw.WriteLine(DateTime.Now);
}
}