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 234645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:12:06+00:00 2026-05-11T20:12:06+00:00

In my case I have five huge text files,which I have to embedd into

  • 0

In my case I have five huge text files,which I have to embedd into one text file.

I tried with StreamReader(),but I don’t know how to make it Read one more file,do I have to assign another variable?

Showing an example will be appreciated greatfully.

  • 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-05-11T20:12:06+00:00Added an answer on May 11, 2026 at 8:12 pm

    New answer

    (See explanation for junking original answer below.)

    static void CopyFiles(string dest, params string[] sources)
    {
        using (TextWriter writer = File.CreateText(dest))
        {
            // Somewhat arbitrary limit, but it won't go on the large object heap
            char[] buffer = new char[16 * 1024]; 
            foreach (string source in sources)
            {
                using (TextReader reader = File.OpenText(source))
                {
                    int charsRead;
                    while ((charsRead = reader.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        writer.Write(buffer, 0, charsRead);
                    }
                }
            }
        }
    }
    

    This new answer is quite like Martin’s approach, except:

    • It reads into a smaller buffer; 16K is going to be acceptable in almost all situations, and won’t end up on the large object heap (which doesn’t get compacted)
    • It reads text data instead of binary data, for two reasons:
      • The code can easily be modified to convert from one encoding to another
      • If each input file contains a byte-order mark, that will be skipped by the reader, instead of ending up with byte-order marks scattered through the output file at input file boundaries

    Original answer

    Martin Stettner pointed out an issue in the answer below – if the first file ends without a newline, it will still create a newline in the output file. Also, it will translate newlines into the “\r\n” even if they were previously just “\r” or “\n”. Finally, it pointlessly risks using large amounts of data for long lines.

    Something like:

    static void CopyFiles(string dest, params string[] sources)
    {
        using (TextWriter writer = File.CreateText(dest))
        {
            foreach (string source in sources)
            {
                using (TextReader reader = File.OpenText(source))
                {
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        writer.WriteLine(line);
                    }
                }
            }
        }
    }
    

    Note that this reads line by line to avoid reading too much into memory at a time. You could make it simpler if you’re happy to read each file completely into memory (still one at a time):

    static void CopyFiles(string dest, params string[] sources)
    {
        using (TextWriter writer = File.CreateText(dest))
        {
            foreach (string source in sources)
            {
                string text = File.ReadAllText(source);
                writer.Write(text);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array which I would like to dump into a table, but
I have a case where i'm getting formatted text with <a href ...> ,
I have a case where I need to serve raw swf files to the
In my case I have panels,but to make it clear I will use buttons
Say for example I have the following string one two(three) (three) four five and
Suppose that a product can have up to five (5) complaints. In this case,
I have a DLL with one single function That gets five doubles and one
Here's my case: I have a table view showing contacts. Add button in the
In general, how expensive is locking in Java? Specifically in my case: I have
I have a case where a 3rd party ad is bleeding through my modal

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.