import java.io.File; import java.util.Scanner; public class DiskFileReading { public static void main(String[] args) throws Exception { String diskFileName = "DemoFile4.txt"; Scanner input = new Scanner(new File(diskFileName)); // To read an entire line, use .nextLine() // To read an integer, use .nextInt(); // Using .next() allows the reading of multiple data values on // a single line (each separated by a space or a TAB) while (input.hasNext()) { String dataValue = input.next(); // Instead of being displayed here, the data values could be // put into a List or a HashMap, or used in some other way System.out.println(dataValue); } } }