C# StreamWriter StreamWriter(String, Boolean, Encoding)
Description
StreamWriter StreamWriter(String, Boolean, Encoding)
Initializes
a new instance of the StreamWriter class for the specified file by using the
specified encoding and default buffer size. If the file exists, it can be
either overwritten or appended to. If the file does not exist, this constructor
creates a new file.
Syntax
StreamWriter.StreamWriter(String, Boolean, Encoding)
has the following syntax.
public StreamWriter(
string path,//ww w . ja v a 2 s. c om
bool append,
Encoding encoding
)
Parameters
StreamWriter.StreamWriter(String, Boolean, Encoding)
has the following parameters.
path
- The complete file path to write to.append
- true to append data to the file; false to overwrite the file. If the specified file does not exist, this parameter has no effect, and the constructor creates a new file.encoding
- The character encoding to use.
Example
The following example demonstrates this constructor.
/* ww w .ja v a 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 (StreamWriter writer = new StreamWriter(fileName, true, Encoding.UTF8))
{
writer.Write(textToAdd);
}
}
}