Re: Append to the end of file when "write"
- From: "PvdG42" <pvdg@xxxxxxxxxxxxx>
- Date: Sun, 14 Oct 2007 22:06:02 -0500
"Curious" <fir5tsight@xxxxxxxxx> wrote in message news:1192416922.311543.194130@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I want to write to an output file, "C:\\temp\\debug.txt": If the file
exists, append the new content to the end of the file (instead of
overwriting the current content). If the file doesn't exist, create
the file and write from the beginning.
Therefore, I want to code this like below:
FileInfo lFile = new FileInfo("C:\\temp\\debug.txt");
if (lFile.Exists)
{
// What's the syntax to append new content (instead of
overwriting the existing content?
FileStream lStream =
lFile.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
}
else
{
FileStream lStream =
lFile.Open(FileMode.OpenOrCreate, FileAccess.Write, FileShare.Read);
}
I believe the append mode is defined at the "lFile.Open" line with the
correct parameters. Thanks!
The FileInfo class exposes an AppendText method, which you may find useful:
http://msdn2.microsoft.com/en-us/library/system.io.fileinfo.appendtext(VS.80).aspx
.
- References:
- Append to the end of file when "write"
- From: Curious
- Append to the end of file when "write"
- Prev by Date: Append mode in write operation
- Next by Date: Re: Append mode in write operation
- Previous by thread: Append to the end of file when "write"
- Next by thread: Append mode in write operation
- Index(es):
Relevant Pages
|