Translate

Tuesday, September 10, 2013

c# write string to file

using System.IO;

namespace WriteToFile
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            string fileLocation = @"C:\OverWrite.txt";

            using (var fileStream = File.Create(fileLocation))
            {
                using (var streamWriter = new StreamWriter(fileStream))
                {
                    streamWriter.WriteLine("Line 1\r\n");
                    streamWriter.WriteLine("Line 2\r\n");
                }
            }
        }
    }

}

No comments:

Post a Comment

Comments will appear once they have been approved by the moderator