Q:

Why does this throw a InputMismatchException?

public class Test
{
    public static void main(String[] args) throws FileNotFoundException
    {
        Scanner input = new Scanner("text.txt");
        int x = input.nextInt();        
    }
}

text.txt being:
8 
8
6  
7

This code throws a InputMismatch Exception. Why?

A:

That is because "text.txt" is not a number. Try:
Scanner input = new Scanner(new File("text.txt"));

