CSharp examples for File IO:Text File
Writing to a Text File
using System;/*w w w . ja v a2 s . c o m*/ using System.IO; public class Writing { public static void Main(String[] args) { if( args.Length < 1 ) { Console.WriteLine("Must include file name."); } else { StreamWriter myFile = File.CreateText(args[0]); myFile.WriteLine("Mary Had a Little Lamb,"); myFile.WriteLine("Whose Fleece Was White as Snow."); for ( int i = 0; i < 10; i++ ) myFile.WriteLine ("{0}", i); myFile.WriteLine("Everywhere that Mary Went,"); myFile.WriteLine("That Lamb was sure to go."); myFile.Close(); } } }