Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8692553
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:20:05+00:00 2026-06-13T00:20:05+00:00

I’ve a console application where I need to read a few .csv files. I’ve

  • 0

I’ve a console application where I need to read a few .csv files.
I’ve no problem to read the two first wich are quite ligth (about 10 000 records each).
But when it start reading the third one (way heavier, about 220 000 records) I keep having error “OutOfMemoryException was unhandled: An unhandled exception of type ‘System.OutOfMemoryException’ occurred in mscorlib.dll”

I don’t understand seen it s working fine for the two first csv…

Here’s my function reading the csv files, the error occurs on the split:

Function FileToString(filePath As String) As String()
    Dim myfile As New StreamReader(filePath, System.Text.Encoding.GetEncoding("iso-8859-1"))
    Dim allData As String = myfile.ReadToEnd()
    Dim rows As String() = allData.Split(vbCr.ToCharArray)
    Return rows
End Function

How could I prevent this? Is there a better way to read csv?
Thanx

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T00:20:06+00:00Added an answer on June 13, 2026 at 12:20 am

    There are 2 things to consider

    1) Instead of String use StringBuilder as
    Dim builder As New StringBuilder

    2) For file reading use buffered approach instead of myfile.ReadToEnd()

    Example

    Function FileToString(filePath As String) As String 
        Dim f As System.IO.FileStream
        Dim mylength As Integer
        Dim i As Integer
    
        f = New System.IO.FileStreamfilePath, IO.FileMode.Open, IO.FileAccess.Read)
    
        Dim streamLength As Integer = Convert.ToInt32(f.Length)
        Dim fileData As Byte() = New Byte(streamLength) {}
    
        f.Read(fileData , 0, streamLength)
        f.Close()
        return fileData.ToString();
    End Function 
    

    And if you want line by line then use below code

    Dim sr As StreamReader = New StreamReader("TestFile.txt")
    Dim line As String
    Do
        line = sr.ReadLine()
        Console.WriteLine(Line)
    Loop Until line Is Nothing
    sr.Close()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've tracked down a weird MySQL problem to the two different ways I was
I have thousands of HTML files to process using Groovy/Java and I need to
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
In my XML file chapters tag has more chapter tag.i need to display chapters
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I don't have much knowledge about the IPv6 protocol, so sorry if the question
I am currently running into a problem where an element is coming back from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.