Friday, March 18, 2005
StreamWriter
StreamWriter is a character stream wrapper that inherits from TextWriter and is used to wrap a byte IO stream.
StreamWriter(Stream stream)
One way is to use a FileStream object as its constructor such as:
A file can be opened directly using the StreamWriter by one of its constructors:
StreamWriter(string fileName)
StreamWriter(string fileName, bool appendFlag)
If appendFlag is true, the output is appended to the end of an existing file. If the file doesn’t exist, it is created.
StreamWriter.Write()
StreamWriter.WriteLine()
StreamWriter(Stream stream)
One way is to use a FileStream object as its constructor such as:
FileStream fout = new FileStream("test.txt", FileMode.Create);Another way is to use the static File members
StreamWriter fileOut = new StreamWriter(fout);
StreamWriter fileOut = File.CreateText("test.txt"); orStreamWriter fileOut = File.AppendText("test.txt"); More Convenient WayA file can be opened directly using the StreamWriter by one of its constructors:
StreamWriter(string fileName)
StreamWriter(string fileName, bool appendFlag)
If appendFlag is true, the output is appended to the end of an existing file. If the file doesn’t exist, it is created.
StreamWriter.Write()
StreamWriter.WriteLine()