Sprache: C#
Fügt Text einem Textfile hinzu
using System.IO;
private void AppendToTxtFile(string strPath, string strLines)
{
StreamWriter myFile = new StreamWriter(strPath, true);
myFile.Write(strLines);
myFile.Close();
}
private void AppendToTxtFile(string strPath, string strLines)
{
StreamWriter myFile = new StreamWriter(strPath, true);
myFile.Write(strLines);
myFile.Close();
}
Alte URL:
/snippet/text-an-textfile-anfuegen/970
Hallo,
so finde ich es etwas eleganter:
[code]private void AppendToTextFile(string strPath, string strLines)
{
using (StreamWriter streamWriter = new StreamWriter(strPath, true))
{
streamWriter.Write(strLines);
}
}[/code]
Jan
Das ist noch kürzer:
[code]File.AppendAllText(strPath, strLines);[/code]