C# StreamWriter StreamWriter(Stream, Encoding)
Description
StreamWriter StreamWriter(Stream, Encoding)
Initializes
a new instance of the StreamWriter class for the specified stream by using
the specified encoding and the default buffer size.
Syntax
StreamWriter.StreamWriter(Stream, Encoding)
has the following syntax.
public StreamWriter(
Stream stream,
Encoding encoding
)
Parameters
StreamWriter.StreamWriter(Stream, Encoding)
has the following parameters.
stream
- The stream to write to.encoding
- The character encoding to use.
Example
The following example demonstrates this constructor.
// w w w . j a v a 2s.c o 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, Encoding.Default))
{
writer.Write(textToAdd);
}
}
}
}