-1

I would like to an a new line to a txt file. I've tried this with StreamWriter but it seems to clear the txt then add the line i want and nothing else. I was just wondering is there away to do where i keep the data inside the txt its adding a line too?

Thanks, Josh

  • You need to use `new StreamWriter("c:\\file.txt", true);` to append to a file rather than overwriting it, see the SO question in the comment by @J3soon for further details. – Alex Dec 31 '15 at 17:59

2 Answers2

2

Simple:

File.AppendAllText("file.txt", "Some Text to Append");

If you want to use StreamWriter then you just need to specify true for the append argument.

new StreamWriter("file.txt", true);
Cyral
  • 13,999
  • 6
  • 50
  • 90
0
var writer = new StreamWriter(fileName, true);
Hatted Rooster
  • 35,759
  • 6
  • 62
  • 122