代码改变世界

c# 文件读取

2015-02-26 11:42  西伯利亚冻原  阅读(140)  评论(0)    收藏  举报

using System;
using System.IO;


class FileTest
{
public static void Main()
{
StreamReader srd;

 string path = @"c:\temp\MyTest.txt";


try
{
srd = File.OpenText (path);

}
catch
{
Console.WriteLine("File open failed");
return;
}
while (srd.Peek() != -1)
{
String str = srd.ReadLine();
Console.WriteLine(str);
Console.ReadKey();
}

}
}