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?
That is because "text.txt"
is not a number. Try:
Scanner input = new Scanner(new File("text.txt"));