In c# , How can we open a file in write mode and write into it.
Printable View
In c# , How can we open a file in write mode and write into it.
Hi,
You can use FileStream class to create or open file and use StreamWriter class to write into file.
Here is an example :
using System.IO;
class TestWriteFile
{
public static void Main()
{
FileStream fs = new FileStream("text.txt", FileMode.Create);
StreamWriter w = new StreamWriter(fs);
w.WriteLine("This is a test string");
w.Flush();
w.Close();
fs.Close();
}
}