0
我正在使用twitter api數據,並將流結果存儲在文本文件中後,我將數據輸入到解析器應用程序中。我計劃的是大數據文件,所以我使用分隔符來讀取內容]}來分隔各個帖子以避免發生錯誤的可能性?備份功能是使用緩衝區讀取數據,然後剪切成單個帖子。 但問題是,在某些情況下,對於單個帖子,會發生內存異常。現在,當我查看單個帖子時,它看起來不是很大,但文本將包含外部字符或一些編碼,我猜這會導致內存異常。我還沒有想出如果正是這樣,但還沒有想到我會得到一些在這裏輸入或意見...outofmemory異常從文件中讀取xml
myreader.TextFieldType = FileIO.FieldType.Delimited
myreader.SetDelimiters("]}}")
Dim currentRow As String()
Try
While Not myreader.EndOfData
Try
currentRow = myreader.ReadFields()
Dim currentField As String
For Each currentField In currentRow
data = data + currentField
counter += 1
If counter = 1000 Then
Dim pt As New parsingUtilities
If Not data = "" Then
pt.getNodes(data)
counter = 0
End If
End If
Next
Catch ex As Exception
If ex.Message.Contains("MemoryException") Then
fileBKup()
End If
End Try
當內存出現異常時,其他時間然後我試圖分裂成不同的職位:
Dim sampleResults() As String
Dim stringSplitter() As String = {"}}"}
' split the file content based on the closing entry tag
sampleResults = Nothing
Try
sampleResults = post.Split(stringSplitter, StringSplitOptions.RemoveEmptyEntries)
Catch ex As Exception
appLogs.constructLog(ex.Message.ToString, True, True)
moveErrorFiles(form1.infile)
Exit Sub
End Try