Page 1 of 1 |
Prev
|
Next
How do I create a text file?
This example show you how to create a text file and write some data into the created text file. In this example we use the TextWriter and StreamWriter class.
using System;
using System.IO;
namespace Kodecsharp.Example.System.IO
{
public class WriteTextFile
{
public static void Main(string[] args)
{
//
// Create a new text file called employee.txt
//
TextWriter writer = new StreamWriter(@"C:\employee.txt");
try
{
//
// Write some string into file.
//
writer.WriteLine("John Riise,30-12-76,10000");
writer.WriteLine("Ricky James,21-02-80,5000");
writer.WriteLine("Sidney Brickstore,07-11-80,5000");
}
finally
{
writer.Flush();
writer.Close();
}
}
}
}