title: Java: How to count the no. of lines in a file?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/453018/number-of-lines-in-a-file-in-java">Number of lines in a file in Java</a>  </p>
  </blockquote>
  
  
  
  <p>I need to count the number of lines of a txt file that is passed to java through a command line argument. I know how to read from a file but i am having trouble doing the rest. any help would be appreciated. 
  here is what i have so far:</p>
  
  <pre><code>   import java.util.*;
     import java.io.*;
     public class LineCounter {
  public static void main (String [] args) throws IOException{
      Scanner file = new Scanner(new File("myFlile.txt"));
      int count = 0;
      while(file.hasNext()){
          boolean s = file.hasNext();
          int count = file.nextInt();
      }
  
      System.out.println(count);
     }
       }
  </code></pre>