This line:
Scanner scanner = new Scanner(new File("Test.txt"));
is inside the curly braces of the try
block. Therefore, it is visible only within those curly braces. To make sure it's visible outside, declare the variable before the try
:
Scanner scanner;
and then, inside the try
block, just assign to it, don't declare it (the difference is that you don't include the type name; that makes it an assignment statement):
scanner = new Scanner(new File("Test.txt"));