C # - Empty txt content, and additional content

C # emptied the contents of txt, and additional content

bruce135lee

1, empty the contents of the 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, the additional content to txt

  1. public void SaveFile(string str,String txtPath,bool saOrAp) {  
  2.   
  3.            String appDir = System.AppDomain.CurrentDomain.BaseDirectory + @"Txt\" + txtPath;  
  4.            StreamWriter sw = new StreamWriter (appDir, saOrAp); // saOrAp denotes a cover or additionally  
  5.            sw.WriteLine(str);  
  6.            sw.Close();  
  7.        }  
Published 17 original articles · won praise 224 · views 280 000 +

Guess you like

Origin blog.csdn.net/cxu123321/article/details/103642273