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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:13:49+00:00 2026-05-25T12:13:49+00:00

How do I split a single text file with 1000 lines into multiple smaller

  • 0

How do I split a single text file with 1000 lines into multiple smaller files of, for example, 300 lines apiece? Please keep in mind that the original file may have more or less than a thousand lines.

file1.txt 300 lines -> rest
file2.txt 300 lines -> rest
file3.txt 300 lines -> rest
file4.txt 100 lines 

I tried the following but it’s not working.

int counter = 0;
string line;

string lineoutput = (current_dir + "\\" + DateTime.Now.ToString("HHmmss") + ".txt");

System.IO.StreamReader inputfile;

inputfile = new System.IO.StreamReader(new_path);
while ((line = inputfile.ReadLine()) != null)
{
    System.IO.StreamWriter file = new System.IO.StreamWriter(current_dir + "\\" + DateTime.Now.ToString("HHmmss") + ".txt", true);

    string _replaceBackspace = ReplaceBackspace(read_file.ReadLine().ToLower());

    using (StreamWriter writer = new StreamWriter(lineoutput, true))
    {
        if (counter == 5000)
        {
            counter = 0;
            lineoutput = (current_dir + "\\" + DateTime.Now.ToString("HHmmss") + ".txt");
        }
        writer.WriteLine(line.ToLower());
    }
    counter++;
}
  • 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-25T12:13:49+00:00Added an answer on May 25, 2026 at 12:13 pm
    string baseName = current_dir + "\\" + DateTime.Now.ToString("HHmmss") + ".";
    
    StreamWriter writer = null;
    try
    {
        using (StreamReader inputfile = new System.IO.StreamReader(new_path))
        {
            int count = 0;
            string line;
            while ((line = inputfile.ReadLine()) != null)
            {
    
                if (writer == null || count > 300)
                {
                    if (writer != null)
                    {
                        writer.Close();
                        writer = null;
                    }
    
                    writer = new System.IO.StreamWriter(baseName + count.ToString() + ".txt", true);
    
                    count = 0;
                }
    
                writer.WriteLine(line.ToLower());
    
                ++count;
            }
        }
    }
    finally
    {
        if (writer != null)
            writer.Close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking to split up multiple lines of text to single them out,
I have split a large text file into a number of sets of smaller
How can I split long commands over multiple lines in a batch file?
I would like to split a text into single words using PHP. Do you
So I've written some code in Ruby to split a text file up into
I have a large dataset split into 5 files (each has 15000 attributes, first
Text file 1 has the following format: 'WORD': 1 'MULTIPLE WORDS': 1 'WORD': 2
Simply Asking, Is there any function available in mysql to split single row elements
I want to split a command line like string in single string parameters. How
I need split string by commas and spaces, but ignore the inside quotes, single

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.