package somePackage; import java.util.*; import java.io.File; import java.io.IOException; public class someClass{ public static void main(String[] args) throws IOException { try { Scanner fileName = new Scanner(new File("C:/myData/names.txt")); int count=0; while(fileName.hasNext()) { String name=fileName.next(); System.out.println(name); count++; }//while: read rest of file if(count>0) { System.out.println(count+" names read"); } else System.out.println("No values found"); fileName.close(); } //try catch (IOException e) { System.out.println("File not found"); } }//main }//class