C# StreamWriter StreamWriter(Stream)
Description
StreamWriter StreamWriter(Stream)
Initializes a new
instance of the StreamWriter class for the specified stream by using UTF-8
encoding and the default buffer size.
Syntax
StreamWriter.StreamWriter(Stream)
has the following syntax.
public StreamWriter(
Stream stream
)
Parameters
StreamWriter.StreamWriter(Stream)
has the following parameters.
stream
- The stream to write to.
Example
The following code example demonstrates this constructor.
//from www. java 2 s . co m
using System;
using System.IO;
using System.Text;
class Program
{
static void Main(string[] args)
{
string fileName = "test.txt";
string textToAdd = "java2s.com";
using (FileStream fs = new FileStream(fileName, FileMode.CreateNew))
{
using (StreamWriter writer = new StreamWriter(fs))
{
writer.Write(textToAdd);
}
}
}
}