how to count the lines in a file using java scanner

how to count the lines in a file using java scanner
/**
 * @author lautturi.com
 * Java example: how to check the lines in file java scanner
 */

import java.util.*;
import java.io.*;

public class Lautturi {

	public static void main(String[] args) throws FileNotFoundException {

		int count = 0;
		Scanner scanner = new Scanner(new File("test.txt"));
		while (scanner.hasNextLine()) {
		    count++;
		    scanner.nextLine();
		}
		System.out.println("file lines:"+count);

	}
}
Source:‮‬www.lautturi.com

output;

file lines:10
Created Time:2017-09-10 11:36:50  Author:lautturi