package cusack; import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; public class PX_ReadOneLine_lastname { public static void main(String[] args) { try { // Reference an existing file File file = new File("input.dat"); // Make sure this file already exists // Create a Scanner to read the file Scanner reader = new Scanner(file); // Read just one line if (reader.hasNextLine()) { String line = reader.nextLine(); System.out.println(line); } else { System.out.println("The file is empty."); } // Close the scanner reader.close(); } catch (FileNotFoundException e) { System.out.println("File not found. Please check the file name or location."); } } }