Tuesday, July 14, 2009

What are the file read & write functions in C# ???

Actually i want to know that what are the file read %26amp; write functions in C#, like fputs(),fgets(), or fprintf(), and fscanf(); and please also mention how to open file in c# . and how to close it.......





please reply............

What are the file read %26amp; write functions in C# ???
Ok, what you're describing is C functions which the concept is expanded in C#. Several objects are used to read and write files. They include the buffered streams, file streams, text read/writers to name a few. Most fall under the system.io class or input/output class of structure. An example is demonstrated below:





using System;


using System.IO;





class FSRead


{


public static void Main()


{


//Create a file stream from an existing file.


FileInfo fi=new FileInfo("c:\\csc.txt");


FileStream fs=fi.OpenRead();





//Read 100 bytes into an array from the specified file.


int nBytes=100;


byte[] ByteArray=new byte[nBytes];


int nBytesRead=fs.Read(ByteArray, 0, nBytes);


Console.WriteLine("{0} bytes have been read from the specified file.", nBytesRead.ToString());


}


}








I've also included some links below.





Hope this helps.

hollyhock

No comments:

Post a Comment