User Tools

Site Tools


wiki:streamwriter

StreamWriter

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CreateFileWriteDataToIt
{
    class Program
    {
        static void Main(string[] args)
        {
            string TextToAdd = "This is my first time creating a text file from my own program!";
            StreamWriter outfile = new StreamWriter("../../myfirstfile.txt");
            // This creates the file in the projects/CreateFileWriteData/CreateFileWriteData/bin directory

            // So we've created the string with the text, and opened an empty file.  Now we fill it.

            outfile.WriteLine(TextToAdd);

            // Now we use outfile to close the file so nothing else can be written there.
            outfile.Close();

        }
    }
}

Awesome!!

wiki/streamwriter.txt · Last modified: 2019/06/23 03:05 by 64.57.171.66