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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted Jun 27, 2007, 12:45 PM
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");
AlanPosted Jun 27, 2007, 12:40 PM
However, crausch's second solution should work fine as this is what the StreamWriter.WriteLine() method itself uses.
crauschPosted Jun 27, 2007, 11:17 AM
StreamWriter sw = new StreamWriter(“path”);
sw.Write("Hello \n World");
or
sw.WriteLine("Hello");
sw.Write("World");