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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:04:14+00:00 2026-05-25T00:04:14+00:00

I Im trying to read from one text file and write to another one.

  • 0

I Im trying to read from one text file and write to another one. The file Im reading from has 2023 lines, and the file that I am writing to comes out with only 2008 lines. I cant figure out what is happening to the other line… Im losing them somewhere. What am I doing wrong?

thanks!

heres my code in C#.

     static void Main(string[] args)
    {
        StreamWriter writer = new StreamWriter("C:/Users/Rafael/desktop/newfile.txt");
        StreamReader reader = new StreamReader("C:/Users/Rafael/desktop/new1.txt");//, System.Text.Encoding.GetEncoding("ISO-8859-1"));
        string line;
        while ((line = reader.ReadLine()) != null)
        {

            writer.WriteLine(line);
        }

    }
  • 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-25T00:04:14+00:00Added an answer on May 25, 2026 at 12:04 am

    At no point here are you closing the streamwriter – so it might not be written to the file. You can test this by putting a Close() call after the loop, or if you have not finished with the file, you can use Flush().

    Given a choice, I would however rewrite the code to use Using{} blocks which would close the streams automatically by calling Dispose() when they go out of scope.

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

Sidebar

Related Questions

I'm trying to read a line of text from a text file and put
I am trying to parse a set of lines read from a file in
I'm trying to create a function to read Morse code from one file, convert
I am trying to read from a text file and tokenize the input. I
I am trying to read in data from a text file (the time). and
I am trying to write a list to a text file that is included
I'm trying to read a text file one line at a time and print
I am trying to read from file: The file is multiline and basically i
I'm trying to read variables from a batch file for later use in the
I'm trying to read data from a.csv file to ouput it on a webpage

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.