小编Spa*_*ter的帖子

在vb.net中读取非常大的文本文件时出现内存不足错误

我的任务是处理一个3.2GB的固定宽度分隔文本文件.每行1563个字符长,文本文件中大约有210万行.读完大约100万行后,我的程序因内存不足异常错误而崩溃.

Imports System.IO
Imports Microsoft.VisualBasic.FileIO

Module TestFileCount
    ''' <summary>
    ''' Gets the total number of lines in a text file by reading a line at a time
    ''' </summary>
    ''' <remarks>Crashes when count reaches 1018890</remarks>
    Sub Main()
        Dim inputfile As String = "C:\Split\BIGFILE.txt"
        Dim count As Int32 = 0
        Dim lineoftext As String = ""

        If File.Exists(inputfile) Then
            Dim _read As New StreamReader(inputfile)
            Try
                While (_read.Peek <> -1)
                    lineoftext = _read.ReadLine()
                    count += 1
                End While

                Console.WriteLine("Total Lines in " …
Run Code Online (Sandbox Code Playgroud)

.net vb.net out-of-memory

5
推荐指数
1
解决办法
5062
查看次数

标签 统计

.net ×1

out-of-memory ×1

vb.net ×1