Implementing File Input Output Operations In C#.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace FileInputOutput
{
class Program
{
public void readdata()
{
FileStream fs = new FileStream("Myfile.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string str = sr.ReadLine();
while (sr != null)
{
Console.Write("{0}", str);
str = sr.ReadLine();
}
sr.Close();
fs.Close();
}
static void Main(string[] args)
{
Program fr = new Program();
fr.readdata();
}
}
}
Output:--
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace FileInputOutput
{
class Program
{
public void readdata()
{
FileStream fs = new FileStream("Myfile.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string str = sr.ReadLine();
while (sr != null)
{
Console.Write("{0}", str);
str = sr.ReadLine();
}
sr.Close();
fs.Close();
}
static void Main(string[] args)
{
Program fr = new Program();
fr.readdata();
}
}
}
Output:--