C# StreamWriter StreamWriter(String, Boolean)
Description
StreamWriter StreamWriter(String, Boolean)
Initializes
a new instance of the StreamWriter class for the specified file by using the
default encoding and 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)
has the following syntax.
public StreamWriter(
string path,
bool append
)
Parameters
StreamWriter.StreamWriter(String, Boolean)
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.
Example
The following code example demonstrates this constructor.
// w ww .j av a2 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))
{
writer.Write(textToAdd);
}
}
}