title: How to truncate/remove contents from a file untill a particular size reaches
body: <p>I have a text file sizes around 10 KB, I need to removes lines one-by-one from the beginning of the file and needs to stop when the file reaches 5 KB . I used the following piece of code, but it is not giving me the accurate results what i want to see ( For ex : If i want to reduce it to 5 KB it stops when it reaches the 6.5 KB)</p>
  
  <pre><code>cacheCutOffSize = 5 * 1024; //(in KB)
  using (StreamWriter sr = new StreamWriter(fileName))
          {
              sr.AutoFlush = true;
              while ((sr.BaseStream.Length &lt; cacheCutOffSize) &amp;&amp; lines.Count &gt; 0) //*8
              {
                  sr.WriteLine(strng);
                  lines.RemoveAt(0);
                  strng = lines[0];
              }
  
          }
  </code></pre>
  
  <p>Is there a better and accurate way for doing this?</p>