创建一个Windows控制台程序StreamReaderDemo。其中主函数代码如下。注意添加System.IO引用。
static void Main(string[] args)
{
try
{
StreamReader m_sr = new StreamReader(@"c:\file.txt");
string m_data = m_sr.ReadToEnd();
Console.WriteLine(m_data);
m_sr.Close();
}
catch (IOException ex)
{
Console.WriteLine(ex);
return;
}
Console.WriteLine("Write to File Succeed!");
}
|