C # emptied the contents of txt, and additional content
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
- public void SaveFile(string str,String txtPath,bool saOrAp) {
- String appDir = System.AppDomain.CurrentDomain.BaseDirectory + @"Txt\" + txtPath;
- StreamWriter sw = new StreamWriter (appDir, saOrAp); // saOrAp denotes a cover or additionally
- sw.WriteLine(str);
- sw.Close();
- }