Console Application
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace pr11
{
class Program
{
static void Main(string[] args)
{
FileInfo f = new FileInfo(@"C:\Documents and Settings\admin\Desktop\SD\file2.txt");
StreamWriter w = f.CreateText();
w.WriteLine("This is from");
w.WriteLine("Chapter 6");
w.WriteLine("Of C# Module");
w.Write(w.NewLine);
w.WriteLine("Thanks for your time");
w.Close();
//
Console.WriteLine("Reading the contents from the file");
StreamReader s = File.OpenText(@"C:\Documents and Settings\admin\Desktop\SD\file2.txt");
string read = null;
while ((read = s.ReadLine()) != null)
{
Console.WriteLine(read);
}
s.Close();
Console.Read();
}
}
}
Filed under: IO | Tagged: files, StreamReader, StreamWriter, Txt Files