使用StreamReader时内存不足异常

时间:2017-04-05 10:51:57

标签: vb.net out-of-memory streamreader

我正在阅读一个大文本文件(300 MB)并将文本转换为DataTable,但是我收到内存不足异常。

代码:

Using sr As StreamReader = New StreamReader(name)
    line = sr.ReadLine()
    While line <> Nothing

        Dim txtLines() As String = line.Split(vbTab)
        If (txtLines.Count > 0) Then
            If (i = 0) Then
                For Each item As String In txtLines
                    dt.Columns.Add(New DataColumn())
                Next
                i = i + 1
            Else
                Dim row As DataRow = dt.NewRow()
                row.ItemArray = txtLines
                dt.Rows.Add(row)
            End If
        End If
        line = sr.ReadLine() //getting error here 
    End While
End Using

0 个答案:

没有答案