title: Best way to write huge string into a file
body: <p>In C#, I'm reading a moderate size of file (100 KB ~ 1 MB), modifying some parts of the content, and finally writing to a different file. All contents are text. Modification is done as string objects and string operations. My current approach is:</p>
  
  <ol>
  <li>Read each line from the original file by using <code>StreamReader</code>.</li>
  <li>Open a <code>StringBuilder</code> for the contents of the new file.</li>
  <li>Modify the string object and call <code>AppendLine</code> of the <code>StringBuilder</code> (until the end of the file)</li>
  <li>Open a new <code>StreamWriter</code>, and write the <code>StringBuilder</code> to the write stream.</li>
  </ol>
  
  <p>However, I've found that <code>StremWriter.Write</code> truncates 32768 bytes (2^16), but the length of <code>StringBuilder</code> is greater than that. I could write a simple loop to guarantee entire string to a file. But, I'm wondering what would be the most efficient way in C# for doing this task?</p>
  
  <p>To summarize, I'd like to modify only some parts of a text file and write to a different file. But, the text file size could be larger than 32768 bytes.</p>
  
  <p>== Answer == I'm sorry to make confusin to you! It was just I didn't call <code>flush</code>. <code>StremWriter.Write</code> does not have a short (e.g., 2^16) limitation.</p>