需要帮助,以使streamreader从文本文件的顶部到底部读取. [英] Need help making streamreader read from the top to bottom lines in a text file.
问题描述
这是我的示例代码:
Using f As System.IO.FileStream = System.IO.File.OpenRead("md5.txt")
Using s As System.IO.StreamReader = New System.IO.StreamReader(f)
While Not s.EndOfStream
Dim line As String = s.ReadLine
Dim sample As String
Dim firstpart As String = line.Substring(0, line.IndexOf(":"))
Dim lastpart As String = line.Substring(line.LastIndexOf(":") + 1)
sample = md5_hash(path)
txtBox1.Text = lastpart
txtBox2.Text = md5_hash(path)
If (txtBox2.Text = sample) Then
lblResult.Text = "Threats Found!"
lblResult.ForeColor = Color.Red
Else
lblResult.Text = "Clean!"
lblResult.ForeColor = Color.Green
End If
End While
End Using
End Using
End If
End Sub
我想在文本文件"md5"中添加行.从第1行读取并显示到最后一行.我不要任何循环.目前,如果我在"md5"中添加多行,文本文件,当它扫描第一行之后的任何行时,它仍然 输出显示第一行及其后任何行的结果.任何帮助将不胜感激.
I want to make the lines in the text file "md5" read and displayed from line 1 to the last line. I don't want any looping. Currently if I add more than one line in the "md5" text file, when it scans any lines after the first one it is still outputting displaying the result for the first line and for any lines after. Any help would be greatly appreciated.
推荐答案
可能您需要此:
Probably you need this:
lblResult.Text = "Clean!"
lblResult.ForeColor = Color.Green
Using f As System.IO.FileStream = System.IO.File.OpenRead("md5.txt")
Using s As System.IO.StreamReader = New System.IO.StreamReader(f)
While Not s.EndOfStream
Dim line As String = s.ReadLine
... check the line for threats ...
If thread found? Then
lblResult.Text = "Threats Found!"
lblResult.ForeColor = Color.Red
Exit While
End If
End While
End Using
End Using
还请检查您的代码.自 txtBox2.Text 起, If 始终为True sample 的值是相同的 md5_hash 值.
Also review your code. Seems that If is always True since txtBox2.Text and sample is the same md5_hash value.
这篇关于需要帮助,以使streamreader从文本文件的顶部到底部读取.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!