What is the use of StreamWriter in C#?

 Posted by vishalneeraj-24503 on 1/28/2014 | Category: C# Interview questions | Views: 3255 | Points: 40

StreamWriter is a class used in Dot Net to write Text into files.As name suggests it writes data to a byte stream.Actually it implements a System.IO.TextWriter class that writes characters to a byte stream in a particular encoding.

We have to give a proper file path in its constructor otherwise it will give FileNotFound error.

DirectoryInfo[] dirs = new DirectoryInfo(@"c:\").GetDirectories();

using (StreamWriter sw = new StreamWriter("name_of_the_file"))
foreach (DirectoryInfo dir in dirs)

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response