StreamWriter sw = new StreamWriter(“path”);
sw.Write(“"Hello \r World"”);
in the above code new line do not appear in the File.
Can some one help me to insert new line in File.
StreamWriter sw = new StreamWriter(“path”);
sw.Write(“"Hello \r World"”);
in the above code new line do not appear in the File.
Can some one help me to insert new line in File.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
crausch55 reputationPosted Jun 27, 2007, 7:17 AM EDT
StreamWriter sw = new StreamWriter(“path”);
sw.Write("Hello \n World");
or
sw.WriteLine("Hello");
sw.Write("World");
AlanRank #669 · 3.6K reputationPosted Jun 27, 2007, 8:40 AM EDT
However, crausch's second solution should work fine as this is what the StreamWriter.WriteLine() method itself uses.
Posted Jun 27, 2007, 8:45 AM EDT
FileStream filePath = new FileStream("this.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(filePath);
sw.WriteLine(
"Input: " + dblInput);sw.WriteLine("Result: " + dblResults);
sw.Close();
filePath.Close();
Or if you you just want insert a newline after one line of text, just put \r\n at the end of the text, like this:
sw.Writeline("Some sort of text\r\n");