Search This Blog

Monday, August 25, 2008

File Read

using System;
using System.IO;

class FileRead

{

string filereadbuf; // buffer to store the content of file

public void ReadFile(string FileName, int FileSize)

{

char[] buf = new char[FileSize];

// lets define an array of type char field (i.e. variable) buf // for more help please see .net sdk StreamReader sr = new StreamReader(new FileStream(FileName, FileMode.Open, FileAccess.Read));

int retval = sr.ReadBlock(buf, 0, FileSize);

// no. of bytes read

Console.Write ("Total Bytes Read = " + retval + "\n");

filereadbuf = new string(buf);

// store it in our field

Console.WriteLine (filereadbuf);

// lets print on screen

sr.Close();

}

}

No comments: