Home » , » Programming: How to create a text file programmatically in C# 2017

Programming: How to create a text file programmatically in C# 2017

 Programming: How to create a text file programmatically in C# 2017

HOW TO CREATE A TEXT FILE IN C# 2017

It is pretty easy to create a text from C# script using the StreamWriter directive. This tutorial will consider the StreamWriter directive, the next tutorial will be how to read a text file in C# and print it in the console! Game programmers need this very often. You may want to create log files, other things. This tutorial is very simple but expandable. If you have any question, drop it in the comment box.

Reading: How to create a text file in C#

StreamWriter implements a System.IO wrapper that writes characters to a stream in a particular encoding. C# makes use of a element referred to as a STREAM to permit applications to work with documents or files. A movement is a link between your software and a data resource. Data can move up or down your Stream so that streams can be used to study and write to files. The stream is the aspect that links your program with the OS of the computer you're using.  Lets put it to use!
[ using System;
//important
using System.IO;
namespace tutorial
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            StreamWriter myWriter = new StreamWriter("My text File");//This will be the title of the text file             myWriter.WriteLine("I am just a text file, tutorials on point");//This will be the actual text
            myWriter.Flush();
       
 }
    }
}
]
The 'writeline' method writes the text to the file.

OUTPUT


I am using Xamarin Studio. You can use any editor of your choice!

The text file will be generated as soon as you launch the program!. In my case, the text file was created in path C:\Users\User\Documents\Projects\tutorial\tutorial\bin\Debug.

If you want to see more of this tutorials like this C#, subscribe to our Newsletter now.
Please Share!

0 comments:

Post a Comment

Get Instant Updates

Subscribe to my Newsletter