title: How do we determine the number of lines in a text file?
body: <p>Hi all I have a local <a href="http://qweop.com/test/airports.dat" rel="nofollow">file</a> which looks like this:</p>
  
  <pre><code>AAA   Anaa
  AAC   EL-ARISH
  AAE   Annaba 
  AAF   APALACHICOLA MUNI AIRPORT
  AAG   ARAPOTI
  AAL   Aalborg Airport
  AAM   Mala Mala
  AAN   Al Ain 
  AAQ   Anapa
  AAR   Aarhus Tirstrup Airport
  AAT   Altay
  AAX   Araxa
  AAY   Al Ghaydah
  ...
  </code></pre>
  
  <p><a href="http://download.oracle.com/javase/tutorial/collections/implementations/QandE/answers.html" rel="nofollow">Java Tutorials</a> suggests estimating the number of lines in a file by doing <a href="http://download.oracle.com/javase/7/docs/api/java/io/File.html#length%28%29" rel="nofollow"><code>java.io.File.length</code></a>
  and dividing the result by 50.</p>
  
  <p>But isn't there a more "solid" way to get the number of lines in a text file (yet without having to pay for the overhead of reading the entire file)?</p>