This will do what you want. You need to open the stream using FileMode.Create, which will create a new file, or write over an existing one. So, assuming that "C:\test.txt" already exists and is filled with some text, this will have the same effect as deleting all of that text.
Code:
using ( FileStream stream = new FileStream( @"C:\test.txt", FileMode.Create ) )
using ( TextWriter writer = new StreamWriter( stream ) )
{
writer.WriteLine( "" );
}
No comments:
Post a Comment