Working with Files Flashcards
1
Q
What does this code do?
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class ReadFile {
public static void main(String[] args) {
try {
File file = new File(“example.txt”);
Scanner scanner = new Scanner(file);
while (scanner.hasNextLine()) { String line = scanner.nextLine(); System.out.println(line); } scanner.close(); } catch (FileNotFoundException e) { System.out.println("File not found: " + e.getMessage()); } } }
A
finds the file Data.txt and read then prints it out line by line