C# StreamWriter StreamWriter(Stream, Encoding, Int32)
Description
StreamWriter StreamWriter(Stream, Encoding, Int32)
Initializes
a new instance of the StreamWriter class for the specified stream by using
the specified encoding and buffer size.
Syntax
StreamWriter.StreamWriter(Stream, Encoding, Int32)
has the following syntax.
public StreamWriter(
Stream stream,/*ww w . j a va2 s.co m*/
Encoding encoding,
int bufferSize
)
Parameters
StreamWriter.StreamWriter(Stream, Encoding, Int32)
has the following parameters.
stream
- The stream to write to.encoding
- The character encoding to use.bufferSize
- The buffer size, in bytes.
Example
The following example demonstrates this constructor.
/*w w w .j av 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.UTF8, 512))
{
writer.Write(textToAdd);
}
}
}
}