
Java
For instance,
Consider a file input.txt:
Hello
How are you?
1 2 3 4 5
You can access it by:
FileReader read = new FileReader("input.txt"); // pass the file name as a String
//now the read is the file
//can scan from the file using Scanner
Scanner scan = new Scanner(read);
System.out.println( scan.nextLine()); // prints Hello
System.out.println( scan.nextLine()); // prints How are you?
while(scan.hasNextInt())
System.out.print(scan.nextInt() + " "); // prints 1 2 3 4 5
Copyright © 2026 eLLeNow.com All Rights Reserved.