Streams

18 09 2008

I tend to use streams quite often when using C#. They are very useful for reading from and writing to files. You can do it using just the StreamReader or StreamWriter classes, however I prefer to use them along with the FileStream class. E.g.

FileStream fs = new FileStream("text.txt");
StreamReader sr = new StreamReader(fs);
Console.WriteLine(sr.ReadToEnd);
sr.Close;
fs.Close;

Don’t forget to close the StreamReader and FileStream to prevent the file becoming locked up!


Actions

Information

Leave a comment