Input/Output 12: StreamWriter
The StreamWriter class is derived from the TextWriter class and can be used to write text to a stream. You can create an instance of the StreamWriter class by assigning it a Stream object returned by a method call, or by passing a file path to one of its constructors. Like the StreamReader class, you can also pass an encoding scheme of your choice to one of its constructors. The most important methods of the StreamWriter class are Write and WriteLine. Write enables you to write a character, an array of characters, or a string. The WriteLine method accepts a String and adds an end-of-line character to the end of the string. For example, the following code opens a new file called NewCompanySecret.txt and writes a string of text to it:
StreamWriter sw = new StreamWriter("
string line = "Don't tell anyone!!!";
Feel free to comment this article using a facebook profile.
I'm using facebook accounts for identification since even akismet couldn't handle all the spam I receive every day.