C#の - 空のtxtコンテンツ、および追加コンテンツ

C#は、TXTの内容、および追加のコンテンツを空に

bruce135lee

1、TXTの内容を空にする

public void ClearTxt(String txtPath)  {  
     String appDir = System.AppDomain.CurrentDomain.BaseDirectory + @"Txt\" + txtPath;  
     FileStream stream = File.Open(appDir, FileMode.OpenOrCreate, FileAccess.Write);  
     stream.Seek(0, SeekOrigin.Begin);  
     stream.SetLength(0);  
     stream.Close();  
}  


2、TXTへの追加コンテンツ

  1. 公共のボイドSAVEFILE(文字列str、文字列txtPath、ブール値saOrAp){  
  2.   
  3.            文字列APPDIR = System.AppDomain.CurrentDomain.BaseDirectory + @ "txtが\" + txtPath。  
  4.            StreamWriter SW =新規のStreamWriter(APPDIR、saOrAp); // saOrApカバーを示し、またはそれに加えて  
  5.            sw.WriteLine(STR)。  
  6.            sw.Close();  
  7.        }  
公開された17元の記事 ウォンの賞賛224 ビュー280 000 +

おすすめ

転載: blog.csdn.net/cxu123321/article/details/103642273