title: Edit a specific Line of a Text File in C#
body: <p>I have two text files, Source.txt and Target.txt. The source will never be modified and contain N lines of text. So, I want to delete a specific line of text in Target.txt, and replace by an specific line of text from Source.txt, I know what number of line I need, actually is the line number 2, both files.</p>
  <p>I haven something like this:</p>
  <pre><code>string line = string.Empty;
  int line_number = 1;
  int line_to_edit = 2;
  
  using StreamReader reader = new StreamReader(@&quot;C:\target.xml&quot;);
  using StreamWriter writer = new StreamWriter(@&quot;C:\target.xml&quot;);
  
  while ((line = reader.ReadLine()) != null)
  {
      if (line_number == line_to_edit)
          writer.WriteLine(line);
  
      line_number++;
  }
  </code></pre>
  <p>But when I open the Writer, the target file get erased, it writes the lines, but, when opened, the target file only contains the copied lines, the rest get lost.</p>
  <p>What can I do?</p>