See the following sample,
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace ReadWriteFromTxt
{
class Program
{
static void readFile()
{
FileStream fsEmp = new FileStream("c:\\Emp.html", FileMode.Open, FileAccess.Read);
StreamReader srEmp = new StreamReader(fsEmp);
string s;
while ((s = srEmp.ReadLine()) != null)
{
Console.WriteLine(s);
Console.Read();
}
srEmp.Close();
fsEmp.Close();
}
static void writeFile()
{
FileStream fsEmp = new FileStream("c:\\Emp.html", FileMode.Open, FileAccess.Write );
StreamWriter swEmp = new StreamWriter(fsEmp );
string s="Have you seen god? Is there anything else to see";
swEmp.WriteLine(s);
swEmp.Close();
fsEmp.Close();
}
static void Main(string[] args)
{
writeFile();
readFile();
}
}
}
www.codecollege.NET
Subscribe to:
Post Comments (Atom)
0 comments
Post a Comment