更新时间:2023-01-31 17:44:31
File.Create
创建该文件,并返回一个打开的流。你并不真的需要所有的逻辑。只需使用新的StreamWriter(path11,真)
这将创建文件,如果它不存在,并追加到它,如果它。此外使用
是有帮助的:
File.Create
creates the file and returns an open stream. You don't really need all that logic. Just use new StreamWriter(path11, true)
which will create the file if it doesn't exist and append to it if it does. Also using
is helpful:
public void WriteToFile(string ProductName)
{
//Get Data from DB and stored in "ProductName"
using (var tw = new StreamWriter(path11, true))
{
tw.WriteLine(ProductName+"@"+DateTime.Now.ToString());
}
}