Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Two issues:</p> <ol> <li>Your <code>FileStream</code>, <code>StreamWriter</code>, and <code>StreamReader</code> classes should be inside <code>using { }</code> blocks. They implement <code>IDisposable</code>, so you need to be calling <code>Dispose</code>, and the <code>using</code> 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 <code>Close()</code>.</li> <li>At a minimum, call <code>mdi_line.Flush()</code> before closing it. This will cause the buffer to be written to the file immediately.</li> </ol> <p>Calling <code>Dispose</code> on the <code>StreamWriter</code> class autmatically calls <code>Flush</code>, which is why the <code>using</code> block will correct the problem.</p> <pre><code>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() &gt;= 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); //} } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload