import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; // Reads all the lines of a file and prints them out using Scanner public class ReadFromFileScanner { public static void main(String[] args) { Scanner sc = null; try { sc = new Scanner(new File("ReadFromFileScanner.java")); while ( sc.hasNextLine() ) { String st = sc.nextLine(); System.out.println(st); } } catch (FileNotFoundException e) { System.out.println("Did not find input file: "+e); } finally { if (sc != null) sc.close(); } } }