所以我的程序基本上需要逐行遍历一个纯文本文件:
Read line 1:
Do commands
loop
Read line2:
Do Commands
loop
等等,直到完成整个文件,是否有人知道任何好的编码示例,所有教程似乎都显示打开和写入/读取文本文件,但没有关于如何逐行执行。
For Each line As String In System.IO.File.ReadAllLines("file.txt")
' Do Something'
Next
你可以这样做:
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