我想使用FileStream并从文件的开头进行查找,同时向前移动文件大小.01%的文件。最有效的方式来跳过一个文件和读取行?
所以我想在文件中寻找一个位置,阅读整个行,如果它符合我的标准,我完成了。如果没有,我会再向前看.01。
虽然C#可以,但VB.NET更受欢迎。
我用来做这样的事情在VB6 ...
FileOpen(1, CurrentFullPath, OpenMode.Input, OpenAccess.Read, OpenShare.Shared)
Dim FileLength As Long = LOF(1)
For x As Single = 0.99 To 0 Step -0.01
Seek(1, CInt(FileLength * x))
Dim S As String = LineInput(1)
S = LineInput(1)
filePosition = Seek(1)
If filePosition < 50000 Then
filePosition = 1
Exit For
End If
V = Split(S, ",")
Dim MessageTime As Date = CDate(V(3) & " " & Mid$(V(4), 1, 8))
Dim Diff As Integer = DateDiff(DateInterval.Minute, MessageTime, CDate(RequestedStartTime))
If Diff >= 2 Then
Exit For
End If
Next
但我不希望使用的FileOpen,我想用一个FileStream。
任何帮助,非常感谢!
你的问题中提到想要在读取只有1%的文件一段时间,但它也说你想逐行阅读,所以我以这种方式回答了它。 – 2009-07-28 21:36:10