Friday, 22 July 2011

StreamReader and StreamWriter classes in .Net

Hi friends,in this post i would like to explain StreamReader & StreamWriter classes in C#.Net.

* StreamReader is used to read data from the file.
* StreamWriter is used to write data into the file.
* Directly we are not write data into the file. First we should write into RAM & then through flush() it will be   written into the file.

StreamReader methods:

1)Read() : Reads single character.
2)ReadLine() : Reads single line.
3)ReadToEnd() : Reads full file.

For Example:

StreamReader str=new StreamReader(file1);
txtBox1.Text=str.ReadToEnd();
str.Close();

StreamWriter methods:

1)Write()
2)WriteLine()

For Example:

StreamWriter stw=new StreamWriter(file1);
stw.Write(txtBox1.Text);
stw.Flush();
stw.Close();

No comments:

Post a Comment