[英]clear content of a text file using TextWriter c#
如何使用TextWriter對象清除文本文件的所有數據?
mt文件名是:user_name.txt
謝謝。
FileMode.Truncate
將從文件中刪除所有文本,然后打開文件進行寫入。
FileInfo fi = new FileInfo(@"C:\path\myfile.txt");
using(TextWriter tw = new StreamWriter(fi.Open(FileMode.Truncate)))
{
tw.Write("write my new text here");
}
將
File.Create(filename).Close();也為你工作?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.