Try Using sr As StreamReader =New StreamReader("c:\aa.txt", Encoding.Default) Dim line AsString Do line = sr.ReadLine Console.WriteLine(line) LoopUntil line IsNothing sr.Close() End Using Catch Ex As Exception Console.WriteLine("The file could not be read:") Console.WriteLine(Ex.Message) EndTry
如果你没有在第二行中构造函数的第二个参数设置为Encoding.Default,你读入的中文文本将是乱码,原因是vs2005为适应新的操作系统,在语言支持上默认为英文标准, 另外一种方法是通过MY.Computer.FileSystem,如 dim sr as system.io.streamReader sr=my.computer.filesystem.openTextfileReader("c:\aa.txt") 把全部文本取回 这个对象的很多属性,方法的使用更是方便简单,这里不做累赘