How to write lines to a text file with TextWriter in C#

2 Answers

0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (TextWriter twriter = File.CreateText("d:\\data.txt"))
            {
                twriter.WriteLine("Text File Line one");
                twriter.WriteLine("Text File Line two");
                twriter.Write("Text File Line three");
            }
        }
    }
}

/*
run:
   
data.txt:
---------
Text File Line one
Text File Line two
Text File Line three

*/


answered Mar 12, 2015 by avibootz
0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (TextWriter twriter = File.CreateText("d:\\data.txt"))
            {
                twriter.Write("a ");
                twriter.Write("b ");
                twriter.Write("c");
            }
        }
    }
}

/*
run:
   
data.txt:
---------
a b c

*/


answered Mar 12, 2015 by avibootz

Related questions

1 answer 179 views
1 answer 154 views
154 views asked Mar 11, 2017 by avibootz
1 answer 196 views
196 views asked Jan 20, 2017 by avibootz
1 answer 177 views
177 views asked Mar 12, 2015 by avibootz
1 answer 192 views
1 answer 174 views
...