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

  • Home
  • SEARCH
  • 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 8394659
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T20:06:58+00:00 2026-06-09T20:06:58+00:00

i have written a program to clean some financial data i have collected over

  • 0

i have written a program to clean some financial data i have collected over the months. it’s about 100GB in total and growing everyday, and each file is about 1-2GB each. it is currently stored in a text file format.

the code below is use to clean the data:

    static void Main()
    {
        string inputString;
        string outputString;

             // others variable omitted

        string[] lineSplit;

        foreach (string fullPath in Directory.GetFiles(inputDirectory))
        {

            using (StreamReader reader = new StreamReader(fullPath))        //read from input file
            {
                while ((line = reader.ReadLine()) != null)
                {
                          //logic to clean data

                                ...

                         ///////////////////////////////////////////////////////////

                    using (StreamWriter writer = File.AppendText(outputFile))
                    {
                        writer.WriteLine(outputString);
                    }
                }
            }
        }       
    }

it is very slow, i estimate for 100GB of data it will take me about 3-4 days to finish it. i know it is about my IO operation, as i have no buffer etc to do it. i am still relatively new to C# and i couldn’t find any relevant example to build a proper buffer for IO. most example i find are for downloading and not applicable to reading text files. And i cant load the whole file into memory to process it as it is too big. how can i do it? can anyone give me some snippet of code i can use? thanks

  • 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-09T20:06:59+00:00Added an answer on June 9, 2026 at 8:06 pm

    You’re reopening the output file on every single line. Move the loop to inside the block which starts by calling File.AppendText:

    using (TextReader reader = File.OpenText(fullPath))
    {
        using (TextWriter writer = File.AppendText(outputFile))
        {
             while ((line = reader.ReadLine()) != null)
             {
                 // Logic to clean data
                writer.WriteLine(outputString);
             }
        }
    }
    

    Of course this assumes you’ve got one output file per input file. If that’s not the case – if each line can go to a different file within a small collection – you may want to keep all the output files open, and just keep a dictionary (or something similar) so you can quickly write to whichever you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written this program, which sorts some ints using a functor: #include<iostream> #include<list>
I have written php program and uploaded on server. I want run this program
I have written a program in VB6. When I compile it and send it
I have written a program that uses qhttp to get a webpage. This works
I have written my program in python. It is written across seven files and
Visual Studio C++ 2008 / GCC 4.4.2 I have written a program to run
I have program written in C. It takes 2 arguments username/password and try to
I have written a java program generates lots of files (say txt files) in
I have written a MapReduce program, code is below: import java.io.IOException; import java.util.Iterator; import
I have written a small program just like hello the world , everything was

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.