For reading input data fast, USACO Guide suggests using a BufferedReader, reading one line at a time, and using a string parser to break the line into individual numbers.
Scanner input = new Scanner(new BufferedReader(new FileReader("file.txt"))); int n = sc.nextInt(); for (int i = 0; i < n; i++) read via sc.nextInt()
In a test I did on a CSES problem, this was only a tiny bit slower than the first approach.
Isn’t the fact it’s a buffered reader supposed to mean it does essentially the same thing under the hood as the first approach? Is there any reason not to use my second approach?