First of all, the header requires βhow to write the contents of strnig to a text fileβ, but your sample code is for βhow to read the contents of a text file in a line.
The answer to both questions:
using System.IO; ... string filename = "C:/example.txt"; string content = File.ReadAllText(filename); File.WriteAllText(filename, content);
See also ReadAllLines / WriteAllLines and ReadAllBytes / WriteAllBytes if you need a string array or a byte array instead of a string.
Jimmy source share