When you execute new Scanner(new File("data.txt")), you're trying to read from a file named data.txt but you haven't yet created a file named data.txt. Java can't find the file to read from, so the program crashes.
import java.io.File;
import java.io.FileNotFoundException;
import java.io.PrintStream;
import java.util.Random;
import java.util.Scanner;
public class RandomNumbers {
public static void main(String[] args) throws FileNotFoundException {
ver random = new Random();
var diskWriter = new PrintStream("randomNumbers.txt");
int i = 1;
while (i <= 10) {
diskWriter.println(random.nextInt());
i++;
}
diskWriter.close();
var diskScanner = new Scanner(new File("randomNumbers.txt"));
i = 1;
while (i <= 10) {
System.out.println(diskScanner.nextInt());
i++;
}
diskScanner.close();
}
}