我想使用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