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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T16:30:54+00:00 2026-05-14T16:30:54+00:00

I am trying to copy a text file in an other text file line

  • 0

I am trying to copy a text file in an other text file line by line. It seems that there is a buffer of 1024 character. If there is less than 1024 character in my file, my function will not copie in the other file.

Also if there is more than 1024 character but less a factor of 1024, these exceeding characters will not be copied.

Ex:

2048 character in initial file – 2048 copied

988 character in initial file – 0 copied

1256 character in initial file – 1024 copied

private void button3_Click(object sender, EventArgs e)
{
    // écrire code pour reprendre le nom  du fichier sélectionné et 
    //ajouter un suffix "_poly.txt"
    string ma_ligne;
    const int RMV_CARCT = 9;

    //délcaration des fichier
    FileStream apt_file = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read);
    textBox1.Text = textBox1.Text.Replace(".txt", "_mod.txt");
    FileStream mdi_file = new FileStream(textBox1.Text, FileMode.OpenOrCreate,FileAccess.ReadWrite);

    //lecture/ecriture des fichiers en question
  StreamReader apt = new StreamReader(apt_file);
  StreamWriter mdi_line = new StreamWriter(mdi_file, System.Text.Encoding.UTF8, 16);



  while (apt.Peek() >= 0)
  {
      ma_ligne = apt.ReadLine();
      //if (ma_ligne.StartsWith("GOTO"))
      //{
      //   ma_ligne = ma_ligne.Remove(0, RMV_CARCT);
      //   ma_ligne = ma_ligne.Replace(" ","");
      //   ma_ligne = ma_ligne.Replace(",", " ");
      mdi_line.WriteLine(ma_ligne);
      //}
  }
  apt_file.Close();
  mdi_file.Close();
}
  • 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-14T16:30:55+00:00Added an answer on May 14, 2026 at 4:30 pm

    Two issues:

    1. Your FileStream, StreamWriter, and StreamReader classes should be inside using { } blocks. They implement IDisposable, so you need to be calling Dispose, and the using block will do that for you. If you do this, that’s actually all you have to fix (which I’ll explain in a minute). Doing this also means you no longer need to call Close().
    2. At a minimum, call mdi_line.Flush() before closing it. This will cause the buffer to be written to the file immediately.

    Calling Dispose on the StreamWriter class autmatically calls Flush, which is why the using block will correct the problem.

    using (FileStream apt_file = new FileStream(textBox1.Text, FileMode.Open, FileAccess.Read))
    {
        textBox1.Text = textBox1.Text.Replace(".txt", "_mod.txt");
    
        using (FileStream mdi_file = new FileStream(textBox1.Text, FileMode.OpenOrCreate, FileAccess.ReadWrite))
        {
            //lecture/ecriture des fichiers en question 
            using (StreamReader apt = new StreamReader(apt_file))
            using (StreamWriter mdi_line = new StreamWriter(mdi_file, System.Text.Encoding.UTF8, 16))
            {
                while (apt.Peek() >= 0)
                {
                    ma_ligne = apt.ReadLine();
                    //if (ma_ligne.StartsWith("GOTO")) 
                    //{ 
                    //   ma_ligne = ma_ligne.Remove(0, RMV_CARCT); 
                    //   ma_ligne = ma_ligne.Replace(" ",""); 
                    //   ma_ligne = ma_ligne.Replace(",", " "); 
                    mdi_line.WriteLine(ma_ligne);
                    //} 
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to copy some text to xml file. The problem is that all
When trying to copy a text file A to another file B, there may
I'm trying to copy both an image from a file and text from a
Part 1 I'm trying to read a text file and then copy into another
I have a text file that contains the following data. The first line is
I am trying to edit a line of a text file (.Hex file) containing
I'm trying to create copy of a mp3 file.This I need to trim that
I'm trying copy a single file from the Plugin directory inside of my Wordpress
I am trying to copy all format file (.txt,.pdf,.doc ...) file from source folder
I am trying to copy the generated program file to the parent directory after

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.