所以我的程序需要逐行查看纯文本文件:
Read line 1:
Do commands
loop
Read line2:
Do Commands
loop
等等,直到完成整个文件,任何人都知道任何好的编码示例,所有教程似乎都显示开放和写/读文本文件,但没有关于如何逐行进行。
答案 0 :(得分:6)
For Each line As String In System.IO.File.ReadAllLines("file.txt")
' Do Something'
Next
答案 1 :(得分:0)
你可以这样做:
Using f As System.IO.FileStream = System.IO.File.OpenRead("somefile.txt")
Using s As System.IO.StreamReader = New System.IO.StreamReader(f)
While Not s.EndOfStream
Dim line As String = s.ReadLine
'put you line processing code here
End While
End Using
End Using