Java: How to count the no. of lines in a file? [duplicate]
Possible Duplicate: Number of lines in a file in Java 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: 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); } } Why