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!

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: