title: Manipulating input and output streams from one file to another
body: <p>I have a new file every few seconds that looks like this:</p>
  
  <blockquote>
    <p>23<br/>
    45<br/>
    21<br/>
    1<br/>
    9<br/>
    23<br/>
    42<br/>
    22<br/>
    40<br/>
    11<br/>
    33<br/>
    32<br/>
    18<br/>
    11<br/>
    12<br/>
    32<br/>
    22<br/>
    7<br/>
    37<br/>
    30</p>
  </blockquote>
  
  <p>In this text file to be read there is one number per line that will be between 1-40. These files are generated several times a minute.</p>
  
  <p>I am trying to order them ascending with <code>StringReader</code> and <code>StringWriter</code>. My logic must be flawed as nothing shows up in this file I intended to send it to. I passed <code>true</code> as the <code>append</code> parameter but still nothing is populated in my sorted file.</p>
  
  <p>The goal was to read from the text file with the <code>for</code> loop which iterates over 1-40 int values and compare that to each string or int from the file read and when found copy that from the read file into the sorted file in sorted order.</p>
  
  <p>I have been looking at it for a while and it should work but does not. Would this be easier with the file reader/writer classes or streamreader/writer as I have done?</p>
  
  <pre><code>public static void ProcessDirectory()
  {
      int variable1;
      StreamReader readToSort = new StreamReader(@"C:write.txt");
      StreamWriter writeSorted = new StreamWriter(@"C:Sorted_File.txt", true);
  
      for (int i = 1; i &gt; 41; i++)
      {
          variable1 = (readToSort.Read());
  
          while (!readToSort.EndOfStream)
          {
              if (variable1 == i)
              {
                  writeSorted.Write(i.ToString() + "\n");
              }
          }
  
          MessageBox.Show("processing #" + variable1);
      }
  
      readToSort.Close();
      writeSorted.Close();
  }
  </code></pre>