• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 661
  • Last Modified:

C# Read Large ASCII-based Data Files one row at a time.

I have a sequential file, where a series of numbers, 1 per row, are about 250 digits long.

Each file has over 60,000 rows.  Some has over 120,000 rows.

Each row will look like this:
01234567889901397819837490187341908734190837419083741902837491087583458934  (this is a string).

What I need to do is read the file one row at a time, without overloading memory and processing power.  I will be processing the whole file at once.

I have the script to do with what it needs to do once I have it, but I need the best way on reading the file one row at a time without overloading memory.

I plan on splitting the row up into parts, then saving the parts into various tables and spreadsheets.

Any help would be greatly appreciated, thanks.
Evan Cutler
Evan Cutler
1 Solution
Mike TomlinsonMiddle School Assistant TeacherCommented:
Standard StreamReader will do it, allowing you to read only one line at a time:
            string line;
            string FileName = @"c:\some path\folder\file.txt";
            StreamReader SR = new StreamReader(FileName);
            while (!SR.EndOfStream)
                line = SR.ReadLine();

                // ... do something with "line" in here...


Open in new window

Evan CutlerVolunteer Chief Information OfficerAuthor Commented:
Thank you very much...
this worked great.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now