C#は、TXTの内容、および追加のコンテンツを空に
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への追加コンテンツ
- 公共のボイドSAVEFILE(文字列str、文字列txtPath、ブール値saOrAp){
- 文字列APPDIR = System.AppDomain.CurrentDomain.BaseDirectory + @ "txtが\" + txtPath。
- StreamWriter SW =新規のStreamWriter(APPDIR、saOrAp); // saOrApカバーを示し、またはそれに加えて
- sw.WriteLine(STR)。
- sw.Close();
- }