C# program that uses FileStream, File.Create
static void Main()
// Use FileStream with File.Create.
// ... Pass FileStream to a StreamWriter and write data to it.
using (FileStream fileStream =
using (StreamWriter writer = new StreamWriter(fileStream))
writer.WriteLine("Example 1 written");
Contents of example1.txt:
Example 1 written
Some notes. It is important to understand how streams can be used together to develop complex (and custom) file handling routines in C#. Many stream types are available.
And: Often the FileStream serves as a "base" to other streams we might use. The example above shows this.