使用StreamWriter写文件
创建一个Windows控制台程序StreamWriteDemo.其中主函数代码如下。注意添加System.IO引用。
ststic void Main(string[] args)
{
try
{
StreamWrite m_sw = new StreamWrite(@"c:\file.txt",true);
m_sw.WriteLine("Another File Operator Method");
m_sw.Close();
}
catch(IOException ex)
{
Console.WriteLine(ex);
return;
}
Console.WriteLine("Write to File Succeed!");
}
|
|