using System;
using System.IO;
class FileRead
{
public void ReadData()
{
FileStream fs
= new FileStream(@"C:\Test
Folder\test.txt", FileMode.Open, FileAccess.Read);
StreamReader sr
= new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string str
= sr.ReadLine();
while (str
!= null)
{
Console.WriteLine("{0}", str);
str =
sr.ReadLine();
}
sr.Close();
fs.Close();
}
public static void Main(String[] args)
{
FileRead fr
= new FileRead();
fr.ReadData();
Console.ReadLine();
}
}
OR
using System;
using System.IO;
class FileRead
{
public void ReadData()
{
FileStream fs
= new FileStream(@"C:\Test
Folder\test.txt", FileMode.Open, FileAccess.Read);
StreamReader sr
= new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string str
= sr.ReadToEnd();
Console.WriteLine("{0}", str);
sr.Close();
fs.Close();
}
public static void Main(String[] args)
{
FileRead fr
= new FileRead();
fr.ReadData();
Console.ReadLine();
}
}
No comments:
Post a Comment